]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMgrReport.h
52090b256b3594ac377bf55c3400e4780fec6966
[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 "msg/Message.h"
19
20 #include "common/perf_counters.h"
21
22 class PerfCounterType
23 {
24 public:
25 std::string path;
26 std::string description;
27 std::string nick;
28 enum perfcounter_type_d type;
29
30 void encode(bufferlist &bl) const
31 {
32 // TODO: decide whether to drop the per-type
33 // encoding here, we could rely on the MgrReport
34 // verisoning instead.
35 ENCODE_START(1, 1, bl);
36 ::encode(path, bl);
37 ::encode(description, bl);
38 ::encode(nick, bl);
39 static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte");
40 ::encode((uint8_t)type, bl);
41 ENCODE_FINISH(bl);
42 }
43
44 void decode(bufferlist::iterator &p)
45 {
46 DECODE_START(1, p);
47 ::decode(path, p);
48 ::decode(description, p);
49 ::decode(nick, p);
50 ::decode((uint8_t&)type, p);
51 DECODE_FINISH(p);
52 }
53 };
54 WRITE_CLASS_ENCODER(PerfCounterType)
55
56 class MMgrReport : public Message
57 {
58 static const int HEAD_VERSION = 2;
59 static const int COMPAT_VERSION = 1;
60
61 public:
62 /**
63 * Client is responsible for remembering whether it has introduced
64 * each perf counter to the server. When first sending a particular
65 * counter, it must inline the counter's schema here.
66 */
67 std::vector<PerfCounterType> declare_types;
68 std::vector<std::string> undeclare_types;
69
70 // For all counters present, sorted by idx, output
71 // as many bytes as are needed to represent them
72
73 // Decode: iterate over the types we know about, sorted by idx,
74 // and use the current type's type to decide how to decode
75 // the next bytes from the bufferlist.
76 bufferlist packed;
77
78 std::string daemon_name;
79
80 void decode_payload() override
81 {
82 bufferlist::iterator p = payload.begin();
83 ::decode(daemon_name, p);
84 ::decode(declare_types, p);
85 ::decode(packed, p);
86 if (header.version >= 2)
87 ::decode(undeclare_types, p);
88 }
89
90 void encode_payload(uint64_t features) override {
91 ::encode(daemon_name, payload);
92 ::encode(declare_types, payload);
93 ::encode(packed, payload);
94 ::encode(undeclare_types, payload);
95 }
96
97 const char *get_type_name() const override { return "mgrreport"; }
98 void print(ostream& out) const override {
99 out << get_type_name() << "(+" << declare_types.size() << "-" << undeclare_types.size()
100 << " packed " << packed.length() << ")";
101 }
102
103 MMgrReport()
104 : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION)
105 {}
106 };
107
108 #endif
109