1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
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.
15 #ifndef CEPH_MMGRREPORT_H_
16 #define CEPH_MMGRREPORT_H_
18 #include <boost/optional.hpp>
20 #include "msg/Message.h"
22 #include "common/perf_counters.h"
28 std::string description;
30 enum perfcounter_type_d type;
32 // For older clients that did not send priority, pretend everything
33 // is "useful" so that mgr plugins filtering on prio will get some
34 // data (albeit probably more than they wanted)
35 uint8_t priority = PerfCountersBuilder::PRIO_USEFUL;
37 void encode(bufferlist &bl) const
39 // TODO: decide whether to drop the per-type
40 // encoding here, we could rely on the MgrReport
41 // verisoning instead.
42 ENCODE_START(2, 1, bl);
44 ::encode(description, bl);
46 static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte");
47 ::encode((uint8_t)type, bl);
48 ::encode(priority, bl);
52 void decode(bufferlist::iterator &p)
56 ::decode(description, p);
58 ::decode((uint8_t&)type, p);
60 ::decode(priority, p);
65 WRITE_CLASS_ENCODER(PerfCounterType)
67 class MMgrReport : public Message
69 static const int HEAD_VERSION = 4;
70 static const int COMPAT_VERSION = 1;
74 * Client is responsible for remembering whether it has introduced
75 * each perf counter to the server. When first sending a particular
76 * counter, it must inline the counter's schema here.
78 std::vector<PerfCounterType> declare_types;
79 std::vector<std::string> undeclare_types;
81 // For all counters present, sorted by idx, output
82 // as many bytes as are needed to represent them
84 // Decode: iterate over the types we know about, sorted by idx,
85 // and use the current type's type to decide how to decode
86 // the next bytes from the bufferlist.
89 std::string daemon_name;
90 std::string service_name; // optional; otherwise infer from entity type
92 // for service registration
93 boost::optional<std::map<std::string,std::string>> daemon_status;
95 void decode_payload() override
97 bufferlist::iterator p = payload.begin();
98 ::decode(daemon_name, p);
99 ::decode(declare_types, p);
101 if (header.version >= 2)
102 ::decode(undeclare_types, p);
103 if (header.version >= 3) {
104 ::decode(service_name, p);
105 ::decode(daemon_status, p);
109 void encode_payload(uint64_t features) override {
110 ::encode(daemon_name, payload);
111 ::encode(declare_types, payload);
112 ::encode(packed, payload);
113 ::encode(undeclare_types, payload);
114 ::encode(service_name, payload);
115 ::encode(daemon_status, payload);
118 const char *get_type_name() const override { return "mgrreport"; }
119 void print(ostream& out) const override {
120 out << get_type_name() << "(";
121 if (service_name.length()) {
124 out << ceph_entity_type_name(get_source().type());
126 out << "." << daemon_name
127 << " +" << declare_types.size()
128 << "-" << undeclare_types.size()
129 << " packed " << packed.length();
131 out << " status=" << daemon_status->size();
137 : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION)