From a9d12cb50a956b78a8f0530da48ea7e68a4f9904 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 23 Apr 2011 15:08:39 -0700 Subject: [PATCH] mon: fix up pg health report Signed-off-by: Sage Weil --- src/mon/PGMap.h | 8 ++++-- src/mon/PGMonitor.cc | 67 +++++++++++++++----------------------------- 2 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index acbd84d843af6..032cfff3ec0d1 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -346,8 +346,7 @@ public: << std::endl; } - void print_summary(ostream& out) const { - std::stringstream ss; + void state_summary(ostream& ss) const { for (hash_map::const_iterator p = num_pg_by_state.begin(); p != num_pg_by_state.end(); ++p) { @@ -355,6 +354,11 @@ public: ss << ", "; ss << p->second << " " << pg_state_string(p->first); } + } + + void print_summary(ostream& out) const { + std::stringstream ss; + state_summary(ss); string states = ss.str(); out << "v" << version << ": " << pg_stat.size() << " pgs: " diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 4a0bf3a01e0f8..a81c2877dc23b 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -875,52 +875,31 @@ bool PGMonitor::prepare_command(MMonCommand *m) enum health_status_t PGMonitor::get_health(std::ostream &ss) const { enum health_status_t ret(HEALTH_OK); + map note; - const hash_map &pg_stat = pg_map.pg_stat; - - hash_map::const_iterator p = pg_stat.begin(); - hash_map::const_iterator p_end = pg_stat.end(); - int seen = 0; + hash_map::const_iterator p = pg_map.num_pg_by_state.begin(); + hash_map::const_iterator p_end = pg_map.num_pg_by_state.end(); for (; p != p_end; ++p) { - seen |= p->second.state; - } - - string prequel(" Some PGs are: "); - if (seen & PG_STATE_CRASHED) { - ss << prequel << "crashed"; - prequel = ","; - } - if (seen & PG_STATE_DOWN) { - ss << prequel << "down"; - prequel = ","; - } - if (seen & PG_STATE_REPLAY) { - ss << prequel << "replaying"; - prequel = ","; - } - if (seen & PG_STATE_SPLITTING) { - ss << prequel << "splitting"; - prequel = ","; - } - if (seen & PG_STATE_DEGRADED) { - ss << prequel << "degraded"; - prequel = ","; - } - if (seen & PG_STATE_INCONSISTENT) { - ss << prequel << "inconsistent"; - prequel = ","; - } - if (seen & PG_STATE_PEERING) { - ss << prequel << "peering"; - prequel = ","; - } - if (seen & PG_STATE_REPAIR) { - ss << prequel << "repairing"; - prequel = ","; - } - if (prequel == ",") { - if (ret > HEALTH_WARN) - ret = HEALTH_WARN; + if (p->first & PG_STATE_DOWN) + note["down"] += p->second; + if (p->first & PG_STATE_DEGRADED) + note["degraded"] += p->second; + if (p->first & PG_STATE_INCONSISTENT) + note["inconsistent"] += p->second; + if (p->first & PG_STATE_PEERING) + note["peering"] += p->second; + if (p->first & PG_STATE_REPAIR) + note["repair"] += p->second; + if (p->first & PG_STATE_SPLITTING) + note["splitting"] += p->second; + } + if (!note.empty()) { + ret = HEALTH_WARN; + for (map::iterator p = note.begin(); p != note.end(); p++) { + if (p != note.begin()) + ss << ", "; + ss << p->second << " pgs " << p->first; + } } return ret; } -- 2.39.5