From 184a9dda8ed08667e17560ff9fb3b60920c09309 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 6 Mar 2012 21:03:39 -0800 Subject: [PATCH] mon: fix full osd detail And use a helper to avoid dup code. Signed-off-by: Sage Weil --- src/mon/PGMonitor.cc | 39 +++++++++++++++------------------------ src/mon/PGMonitor.h | 3 +++ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 011ee2534b484..ff0f0a9c21a89 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -1229,35 +1229,26 @@ void PGMonitor::get_health(list >& summary, detail->push_back(make_pair(HEALTH_WARN, "recovery " + rss.str())); } - if (pg_map.nearfull_osds.size() > 0) { - ostringstream ss; - ss << pg_map.nearfull_osds.size() << " near full osd(s)"; - summary.push_back(make_pair(HEALTH_WARN, ss.str())); - if (detail) { - for (set::iterator p = pg_map.nearfull_osds.begin(); - p != pg_map.nearfull_osds.end(); - ++p) { - ostringstream ss; - const osd_stat_t& os = pg_map.osd_stat.find(*p)->second; - int ratio = (int)(((float)os.kb_used) / (float) os.kb * 100.0); - ss << "osd." << *p << " is near full at " << ratio << "%"; - detail->push_back(make_pair(HEALTH_WARN, ss.str())); - } - } - } - if (pg_map.full_osds.size() > 0) { + check_full_osd_health(summary, detail, pg_map.full_osds, "full", HEALTH_ERR); + check_full_osd_health(summary, detail, pg_map.nearfull_osds, "near full", HEALTH_WARN); +} + +void PGMonitor::check_full_osd_health(list >& summary, + list > *detail, + const set& s, const char *desc, + health_status_t sev) const +{ + if (s.size() > 0) { ostringstream ss; - ss << pg_map.full_osds.size() << " full osd(s)"; - summary.push_back(make_pair(HEALTH_WARN, ss.str())); + ss << s.size() << " " << desc << " osd(s)"; + summary.push_back(make_pair(sev, ss.str())); if (detail) { - for (set::iterator p = pg_map.nearfull_osds.begin(); - p != pg_map.nearfull_osds.end(); - ++p) { + for (set::const_iterator p = s.begin(); p != s.end(); ++p) { ostringstream ss; const osd_stat_t& os = pg_map.osd_stat.find(*p)->second; int ratio = (int)(((float)os.kb_used) / (float) os.kb * 100.0); - ss << "osd." << *p << " is full at " << ratio << "%"; - detail->push_back(make_pair(HEALTH_WARN, ss.str())); + ss << "osd." << *p << " is " << desc << " at " << ratio << "%"; + detail->push_back(make_pair(sev, ss.str())); } } } diff --git a/src/mon/PGMonitor.h b/src/mon/PGMonitor.h index aa0eda73fb592..dad27db892bc0 100644 --- a/src/mon/PGMonitor.h +++ b/src/mon/PGMonitor.h @@ -138,6 +138,9 @@ public: void get_health(list >& summary, list > *detail) const; + void check_full_osd_health(list >& summary, + list > *detail, + const set& s, const char *desc, health_status_t sev) const; private: // no copying allowed -- 2.39.5