]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMgrReport.h
f6af6dfb86aa06a0da4b0e1744fba0e1916ab6c1
[ceph.git] / ceph / src / messages / MMgrReport.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13
14
15 #ifndef CEPH_MMGRREPORT_H_
16 #define CEPH_MMGRREPORT_H_
17
18 #include <boost/optional.hpp>
19
20 #include "msg/Message.h"
21
22 #include "common/perf_counters.h"
23 #include "osd/OSDHealthMetric.h"
24
25 class PerfCounterType
26 {
27 public:
28 std::string path;
29 std::string description;
30 std::string nick;
31 enum perfcounter_type_d type;
32
33 // For older clients that did not send priority, pretend everything
34 // is "useful" so that mgr plugins filtering on prio will get some
35 // data (albeit probably more than they wanted)
36 uint8_t priority = PerfCountersBuilder::PRIO_USEFUL;
37
38 void encode(bufferlist &bl) const
39 {
40 // TODO: decide whether to drop the per-type
41 // encoding here, we could rely on the MgrReport
42 // verisoning instead.
43 ENCODE_START(2, 1, bl);
44 ::encode(path, bl);
45 ::encode(description, bl);
46 ::encode(nick, bl);
47 static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte");
48 ::encode((uint8_t)type, bl);
49 ::encode(priority, bl);
50 ENCODE_FINISH(bl);
51 }
52
53 void decode(bufferlist::iterator &p)
54 {
55 DECODE_START(2, p);
56 ::decode(path, p);
57 ::decode(description, p);
58 ::decode(nick, p);
59 ::decode((uint8_t&)type, p);
60 if (struct_v >= 2) {
61 ::decode(priority, p);
62 }
63 DECODE_FINISH(p);
64 }
65 };
66 WRITE_CLASS_ENCODER(PerfCounterType)
67
68 class MMgrReport : public Message
69 {
70 static const int HEAD_VERSION = 5;
71 static const int COMPAT_VERSION = 1;
72
73 public:
74 /**
75 * Client is responsible for remembering whether it has introduced
76 * each perf counter to the server. When first sending a particular
77 * counter, it must inline the counter's schema here.
78 */
79 std::vector<PerfCounterType> declare_types;
80 std::vector<std::string> undeclare_types;
81
82 // For all counters present, sorted by idx, output
83 // as many bytes as are needed to represent them
84
85 // Decode: iterate over the types we know about, sorted by idx,
86 // and use the current type's type to decide how to decode
87 // the next bytes from the bufferlist.
88 bufferlist packed;
89
90 std::string daemon_name;
91 std::string service_name; // optional; otherwise infer from entity type
92
93 // for service registration
94 boost::optional<std::map<std::string,std::string>> daemon_status;
95
96 std::vector<OSDHealthMetric> osd_health_metrics;
97
98 void decode_payload() override
99 {
100 bufferlist::iterator p = payload.begin();
101 ::decode(daemon_name, p);
102 ::decode(declare_types, p);
103 ::decode(packed, p);
104 if (header.version >= 2)
105 ::decode(undeclare_types, p);
106 if (header.version >= 3) {
107 ::decode(service_name, p);
108 ::decode(daemon_status, p);
109 }
110 if (header.version >= 5) {
111 ::decode(osd_health_metrics, p);
112 }
113 }
114
115 void encode_payload(uint64_t features) override {
116 ::encode(daemon_name, payload);
117 ::encode(declare_types, payload);
118 ::encode(packed, payload);
119 ::encode(undeclare_types, payload);
120 ::encode(service_name, payload);
121 ::encode(daemon_status, payload);
122 ::encode(osd_health_metrics, payload);
123 }
124
125 const char *get_type_name() const override { return "mgrreport"; }
126 void print(ostream& out) const override {
127 out << get_type_name() << "(";
128 if (service_name.length()) {
129 out << service_name;
130 } else {
131 out << ceph_entity_type_name(get_source().type());
132 }
133 out << "." << daemon_name
134 << " +" << declare_types.size()
135 << "-" << undeclare_types.size()
136 << " packed " << packed.length();
137 if (daemon_status) {
138 out << " status=" << daemon_status->size();
139 }
140 if (!osd_health_metrics.empty()) {
141 out << " osd_metrics=" << osd_health_metrics.size();
142 }
143 out << ")";
144 }
145
146 MMgrReport()
147 : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION)
148 {}
149 };
150
151 #endif
152