]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move health check into helper function
authorSage Weil <sage@inktank.com>
Fri, 18 May 2012 21:08:11 +0000 (14:08 -0700)
committerSage Weil <sage@inktank.com>
Fri, 18 May 2012 21:08:11 +0000 (14:08 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 0a01a2936eb0b7aee57c2c3248933771bcddc1d8..4c1f3a711f6479218eef56aec00a192e09489b59 100644 (file)
@@ -962,6 +962,41 @@ void Monitor::_mon_status(ostream& ss)
   jf.flush(ss);
 }
 
+void Monitor::get_health(string& status, bufferlist *detailbl)
+{
+  list<pair<health_status_t,string> > summary;
+  list<pair<health_status_t,string> > detail;
+  for (vector<PaxosService*>::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<pair<health_status_t,string> > summary;
-      list<pair<health_status_t,string> > detail;
-      for (vector<PaxosService*>::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") {
index b20511146e1153b59ebb31edd2d3c80ca96eaf3f..2cf308f6aab91486b0dc5d5c956bb3ac900cd1fd 100644 (file)
@@ -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);