]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: generalize health check a bit
authorSage Weil <sage.weil@dreamhost.com>
Sat, 23 Apr 2011 22:07:32 +0000 (15:07 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Sat, 23 Apr 2011 22:07:32 +0000 (15:07 -0700)
Any PaxosService can return a status (or not).

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc
src/mon/PaxosService.h

index 543530c49b650692b4e01df8886f1705a8f9e251..a342445bd728fe3482ce902bc715703050a7868e 100644 (file)
@@ -342,8 +342,28 @@ void Monitor::handle_command(MMonCommand *m)
       return;
     }
     if (m->cmd[0] == "health") {
-      monmon()->dispatch(m);
-      return;
+      health_status_t overall = HEALTH_OK;
+      string combined;
+      for (vector<PaxosService*>::iterator p = paxos_service.begin();
+          p != paxos_service.end();
+          p++) {
+       PaxosService *s = *p;
+       ostringstream oss;
+       health_status_t ret = s->get_health(oss);
+       if (ret < overall)
+         overall = ret;
+       string cur = oss.str();
+       if (cur.length()) {
+         if (combined.length())
+           combined += "; ";
+         combined += cur;
+       }
+      }
+      
+      stringstream ss;
+      ss << overall << " " << combined;
+      rs = ss.str();
+      r = 0;
     }
   } else 
     rs = "no command";
index 46267b43c423004a83eee8ea5a2f0461cef305b5..39f9cc84c80205852ae4ffb66d46691be8f13f93 100644 (file)
@@ -152,28 +152,6 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
     else if (m->cmd[1] == "remove")
       return false;
   }
-  else if (m->cmd[0] == "health") {
-    ostringstream oss;
-    health_status_t overall = HEALTH_OK;
-    try {
-      health_status_t ret;
-      ret = mon->mdsmon()->get_health(oss);
-      if (ret < overall)
-       overall = ret;
-      ret = mon->osdmon()->get_health(oss);
-      if (ret < overall)
-       overall = ret;
-      ret = mon->pgmon()->get_health(oss);
-      if (ret < overall)
-       overall = ret;
-    }
-    catch (const std::exception &e) {
-      oss << " monmapmonitor: caught exception while "
-         << "checking health: '" << e.what() << "'";
-    }
-    ss << overall << oss.str();
-    r = 0;
-  }
 
   if (r != -1) {
     string rs;
index 18570a3327ba5b64a8526ed68b878d8995b16b82..8d903b7f255816fa9cae3baca8ff743d423dc3ef 100644 (file)
@@ -171,6 +171,8 @@ public:
 
   virtual void init() {}
 
+  virtual enum health_status_t get_health(std::ostream& os) const { return HEALTH_OK; }
+
 };
 
 #endif