]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/OSDHealthMetricCollector.cc
update sources to v12.2.3
[ceph.git] / ceph / src / mgr / OSDHealthMetricCollector.cc
1 #include <boost/format.hpp>
2
3 #include "include/health.h"
4 #include "include/types.h"
5 #include "OSDHealthMetricCollector.h"
6
7
8 using namespace std;
9
10 ostream& operator<<(ostream& os,
11 const OSDHealthMetricCollector::DaemonKey& daemon) {
12 return os << daemon.first << "." << daemon.second;
13 }
14
15 namespace {
16
17 class PendingPGs final : public OSDHealthMetricCollector {
18 bool _is_relevant(osd_metric type) const override {
19 return type == osd_metric::PENDING_CREATING_PGS;
20 }
21 health_check_t& _get_check(health_check_map_t& cm) const override {
22 return cm.get_or_add("PENDING_CREATING_PGS", HEALTH_WARN, "");
23 }
24 bool _update(const DaemonKey& osd,
25 const OSDHealthMetric& metric) override {
26 value.n += metric.get_n();
27 if (metric.get_n()) {
28 osds.push_back(osd);
29 return true;
30 } else {
31 return false;
32 }
33 }
34 void _summarize(health_check_t& check) const override {
35 if (osds.empty()) {
36 return;
37 }
38 static const char* fmt = "%1% PGs pending on creation";
39 check.summary = boost::str(boost::format(fmt) % value.n);
40 ostringstream ss;
41 if (osds.size() > 1) {
42 ss << "osds " << osds << " have pending PGs.";
43 } else {
44 ss << osds.front() << " has pending PGs";
45 }
46 check.detail.push_back(ss.str());
47 }
48 vector<DaemonKey> osds;
49 };
50
51 } // anonymous namespace
52
53 unique_ptr<OSDHealthMetricCollector>
54 OSDHealthMetricCollector::create(osd_metric m)
55 {
56 switch (m) {
57 case osd_metric::PENDING_CREATING_PGS:
58 return unique_ptr<OSDHealthMetricCollector>{new PendingPGs};
59 default:
60 return unique_ptr<OSDHealthMetricCollector>{};
61 }
62 }