]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
224ce89b WB |
18 | #include <boost/optional.hpp> |
19 | ||
7c673cae FG |
20 | #include "msg/Message.h" |
21 | ||
22 | #include "common/perf_counters.h" | |
b32b8144 | 23 | #include "osd/OSDHealthMetric.h" |
7c673cae FG |
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 | ||
3efd9988 FG |
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; | |
1adf2230 | 37 | enum unit_t unit; |
3efd9988 | 38 | |
7c673cae FG |
39 | void encode(bufferlist &bl) const |
40 | { | |
41 | // TODO: decide whether to drop the per-type | |
42 | // encoding here, we could rely on the MgrReport | |
43 | // verisoning instead. | |
1adf2230 | 44 | ENCODE_START(3, 1, bl); |
7c673cae FG |
45 | ::encode(path, bl); |
46 | ::encode(description, bl); | |
47 | ::encode(nick, bl); | |
48 | static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte"); | |
49 | ::encode((uint8_t)type, bl); | |
3efd9988 | 50 | ::encode(priority, bl); |
1adf2230 | 51 | ::encode((uint8_t)unit, bl); |
7c673cae FG |
52 | ENCODE_FINISH(bl); |
53 | } | |
54 | ||
55 | void decode(bufferlist::iterator &p) | |
56 | { | |
1adf2230 | 57 | DECODE_START(3, p); |
7c673cae FG |
58 | ::decode(path, p); |
59 | ::decode(description, p); | |
60 | ::decode(nick, p); | |
61 | ::decode((uint8_t&)type, p); | |
3efd9988 FG |
62 | if (struct_v >= 2) { |
63 | ::decode(priority, p); | |
64 | } | |
1adf2230 AA |
65 | if (struct_v >= 3) { |
66 | ::decode((uint8_t&)unit, p); | |
67 | } | |
7c673cae FG |
68 | DECODE_FINISH(p); |
69 | } | |
70 | }; | |
71 | WRITE_CLASS_ENCODER(PerfCounterType) | |
72 | ||
73 | class MMgrReport : public Message | |
74 | { | |
b32b8144 | 75 | static const int HEAD_VERSION = 5; |
7c673cae FG |
76 | static const int COMPAT_VERSION = 1; |
77 | ||
78 | public: | |
79 | /** | |
80 | * Client is responsible for remembering whether it has introduced | |
81 | * each perf counter to the server. When first sending a particular | |
82 | * counter, it must inline the counter's schema here. | |
83 | */ | |
84 | std::vector<PerfCounterType> declare_types; | |
85 | std::vector<std::string> undeclare_types; | |
86 | ||
87 | // For all counters present, sorted by idx, output | |
88 | // as many bytes as are needed to represent them | |
89 | ||
90 | // Decode: iterate over the types we know about, sorted by idx, | |
91 | // and use the current type's type to decide how to decode | |
92 | // the next bytes from the bufferlist. | |
93 | bufferlist packed; | |
94 | ||
95 | std::string daemon_name; | |
224ce89b WB |
96 | std::string service_name; // optional; otherwise infer from entity type |
97 | ||
98 | // for service registration | |
99 | boost::optional<std::map<std::string,std::string>> daemon_status; | |
7c673cae | 100 | |
b32b8144 FG |
101 | std::vector<OSDHealthMetric> osd_health_metrics; |
102 | ||
7c673cae FG |
103 | void decode_payload() override |
104 | { | |
105 | bufferlist::iterator p = payload.begin(); | |
106 | ::decode(daemon_name, p); | |
107 | ::decode(declare_types, p); | |
108 | ::decode(packed, p); | |
109 | if (header.version >= 2) | |
110 | ::decode(undeclare_types, p); | |
224ce89b WB |
111 | if (header.version >= 3) { |
112 | ::decode(service_name, p); | |
113 | ::decode(daemon_status, p); | |
114 | } | |
b32b8144 FG |
115 | if (header.version >= 5) { |
116 | ::decode(osd_health_metrics, p); | |
117 | } | |
7c673cae FG |
118 | } |
119 | ||
120 | void encode_payload(uint64_t features) override { | |
121 | ::encode(daemon_name, payload); | |
122 | ::encode(declare_types, payload); | |
123 | ::encode(packed, payload); | |
124 | ::encode(undeclare_types, payload); | |
224ce89b WB |
125 | ::encode(service_name, payload); |
126 | ::encode(daemon_status, payload); | |
b32b8144 | 127 | ::encode(osd_health_metrics, payload); |
7c673cae FG |
128 | } |
129 | ||
130 | const char *get_type_name() const override { return "mgrreport"; } | |
131 | void print(ostream& out) const override { | |
224ce89b WB |
132 | out << get_type_name() << "("; |
133 | if (service_name.length()) { | |
134 | out << service_name; | |
135 | } else { | |
136 | out << ceph_entity_type_name(get_source().type()); | |
137 | } | |
138 | out << "." << daemon_name | |
139 | << " +" << declare_types.size() | |
140 | << "-" << undeclare_types.size() | |
141 | << " packed " << packed.length(); | |
142 | if (daemon_status) { | |
143 | out << " status=" << daemon_status->size(); | |
144 | } | |
b32b8144 FG |
145 | if (!osd_health_metrics.empty()) { |
146 | out << " osd_metrics=" << osd_health_metrics.size(); | |
147 | } | |
224ce89b | 148 | out << ")"; |
7c673cae FG |
149 | } |
150 | ||
151 | MMgrReport() | |
152 | : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION) | |
153 | {} | |
154 | }; | |
155 | ||
156 | #endif | |
157 |