From: Sage Weil Date: Fri, 18 May 2012 21:08:11 +0000 (-0700) Subject: mon: move health check into helper function X-Git-Tag: v0.48argonaut~137^2~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7d6facc03d1b97a28d5178411882fb34a80c80d7;p=ceph.git mon: move health check into helper function Signed-off-by: Sage Weil --- diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 0a01a2936eb0..4c1f3a711f64 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -962,6 +962,41 @@ void Monitor::_mon_status(ostream& ss) jf.flush(ss); } +void Monitor::get_health(string& status, bufferlist *detailbl) +{ + list > summary; + list > detail; + for (vector::iterator p = paxos_service.begin(); + p != paxos_service.end(); + p++) { + PaxosService *s = *p; + s->get_health(summary, detailbl ? &detail : NULL); + } + + stringstream ss; + health_status_t overall = HEALTH_OK; + if (!summary.empty()) { + ss << ' '; + while (!summary.empty()) { + if (overall > summary.front().first) + overall = summary.front().first; + ss << summary.front().second; + summary.pop_front(); + if (!summary.empty()) + ss << "; "; + } + } + stringstream fss; + fss << overall; + status = fss.str() + ss.str(); + + while (!detail.empty()) { + detailbl->append(detail.front().second); + detailbl->append('\n'); + detail.pop_front(); + } +} + void Monitor::handle_command(MMonCommand *m) { if (m->fsid != monmap->fsid) { @@ -1074,37 +1109,7 @@ void Monitor::handle_command(MMonCommand *m) r = 0; } if (m->cmd[0] == "health") { - list > summary; - list > detail; - for (vector::iterator p = paxos_service.begin(); - p != paxos_service.end(); - p++) { - PaxosService *s = *p; - ostringstream oss; - s->get_health(summary, (m->cmd.size() > 1) ? &detail : NULL); - } - - stringstream ss; - health_status_t overall = HEALTH_OK; - if (!summary.empty()) { - ss << ' '; - while (!summary.empty()) { - if (overall > summary.front().first) - overall = summary.front().first; - ss << summary.front().second; - summary.pop_front(); - if (!summary.empty()) - ss << "; "; - } - } - stringstream fss; - fss << overall; - rs = fss.str() + ss.str(); - while (!detail.empty()) { - rdata.append(detail.front().second); - rdata.append('\n'); - detail.pop_front(); - } + get_health(rs, (m->cmd.size() > 1) ? &rdata : NULL); r = 0; } if (m->cmd[0] == "heap") { diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index b20511146e11..2cf308f6aab9 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -269,6 +269,14 @@ public: void handle_command(class MMonCommand *m); void handle_route(MRoute *m); + /** + * generate health report + * + * @param status one-line status summary + * @param detailbl optional bufferlist* to fill with a detailed report + */ + void get_health(string& status, bufferlist *detailbl); + void reply_command(MMonCommand *m, int rc, const string &rs, version_t version); void reply_command(MMonCommand *m, int rc, const string &rs, bufferlist& rdata, version_t version);