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