]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/DaemonHealthMetric.h
ad3ea29efd46b14916fb961759a50744a184e3e6
[ceph.git] / ceph / src / mgr / DaemonHealthMetric.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <cstdint>
7 #include <ostream>
8 #include "include/denc.h"
9
10 enum class daemon_metric : uint8_t {
11 SLOW_OPS,
12 PENDING_CREATING_PGS,
13 NONE,
14 };
15
16 static inline const char *daemon_metric_name(daemon_metric t) {
17 switch (t) {
18 case daemon_metric::SLOW_OPS: return "SLOW_OPS";
19 case daemon_metric::PENDING_CREATING_PGS: return "PENDING_CREATING_PGS";
20 case daemon_metric::NONE: return "NONE";
21 default: return "???";
22 }
23 }
24
25 union daemon_metric_t {
26 struct {
27 uint32_t n1;
28 uint32_t n2;
29 };
30 uint64_t n;
31 daemon_metric_t(uint32_t x, uint32_t y)
32 : n1(x), n2(y)
33 {}
34 daemon_metric_t(uint64_t x = 0)
35 : n(x)
36 {}
37 };
38
39 class DaemonHealthMetric
40 {
41 public:
42 DaemonHealthMetric() = default;
43 DaemonHealthMetric(daemon_metric type_, uint64_t n)
44 : type(type_), value(n)
45 {}
46 DaemonHealthMetric(daemon_metric type_, uint32_t n1, uint32_t n2)
47 : type(type_), value(n1, n2)
48 {}
49 daemon_metric get_type() const {
50 return type;
51 }
52 uint64_t get_n() const {
53 return value.n;
54 }
55 uint32_t get_n1() const {
56 return value.n1;
57 }
58 uint32_t get_n2() const {
59 return value.n2;
60 }
61 DENC(DaemonHealthMetric, v, p) {
62 DENC_START(1, 1, p);
63 denc(v.type, p);
64 denc(v.value.n, p);
65 DENC_FINISH(p);
66 }
67
68 friend std::ostream& operator<<(std::ostream& out, const DaemonHealthMetric& m) {
69 return out << daemon_metric_name(m.get_type()) << "("
70 << m.get_n() << "|(" << m.get_n1() << "," << m.get_n2() << "))";
71 }
72 private:
73 daemon_metric type = daemon_metric::NONE;
74 daemon_metric_t value;
75 };
76 WRITE_CLASS_DENC(DaemonHealthMetric)