]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add 'ceph health' command
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 11 Oct 2010 23:42:35 +0000 (16:42 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 12 Oct 2010 21:35:53 +0000 (14:35 -0700)
Create MDSMonitor::get_health and OSDMonitor::get_health to check the
health of the MDSes and OSDes, respectively.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/include/types.h
src/mon/MDSMonitor.cc
src/mon/MDSMonitor.h
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index e439924867d871feb9639204c3b44be25566d25e..b747ed579e27baf54850d536e7af7518ea2046cf 100644 (file)
@@ -477,4 +477,27 @@ inline ostream& operator<<(ostream& out, const ceph_mon_subscribe_item& i)
             << ((i.flags & CEPH_SUBSCRIBE_ONETIME) ? "" : "+");
 }
 
+enum health_status_t {
+  HEALTH_ERR = 0,
+  HEALTH_WARN = 1,
+  HEALTH_OK = 2,
+};
+
+#ifdef __cplusplus
+inline ostream& operator<<(ostream &oss, health_status_t status) {
+  switch (status) {
+    case HEALTH_ERR:
+      oss << "HEALTH_ERR";
+      break;
+    case HEALTH_WARN:
+      oss << "HEALTH_WARN";
+      break;
+    case HEALTH_OK:
+      oss << "HEALTH_OK";
+      break;
+  }
+  return oss;
+};
+#endif
+
 #endif
index 642d9f170764fb0b466a0770430a7d20d71a2931..4c87a150990c49c03a0be649aaa8d11a44b257fe 100644 (file)
@@ -414,6 +414,24 @@ void MDSMonitor::committed()
   tick();
 }
 
+enum health_status_t MDSMonitor::get_health(std::ostream &ss)
+{
+  health_status_t ret(HEALTH_OK);
+
+  bool ok = true;
+  if (mdsmap.is_stopped()) {
+    ss << "mdsmap: STATUS_ERROR. Mdsmap is stopped! ";
+    ret = HEALTH_ERR;
+  }
+  else if (!mdsmap.is_full()) {
+    ss << "mdsmap: STATUS_WARN. Mdsmap is not full. ";
+    ret = HEALTH_WARN;
+  }
+  if (ret > HEALTH_OK) {
+    ss << "mdsmap: " << "'" << mdsmap << "'" << std::endl;
+  }
+  return ret;
+}
 
 bool MDSMonitor::preprocess_command(MMonCommand *m)
 {
index 3bb6e724bc02a47d224674fd01350f309c2a1380..ba05d048c87d01d449effff4afc2932791eb9612 100644 (file)
@@ -83,6 +83,7 @@ class MDSMonitor : public PaxosService {
   bool preprocess_offload_targets(MMDSLoadTargets *m);
   bool prepare_offload_targets(MMDSLoadTargets *m);
 
+  enum health_status_t get_health(std::ostream &ss);
   bool preprocess_command(MMonCommand *m);
   bool prepare_command(MMonCommand *m);
 
index 37ee6db4f6a482b68dbacf142c69262d24821aac..54a387edba03cc0e1c15133e803b5e5f066d2565 100644 (file)
@@ -298,6 +298,7 @@ void Monitor::handle_command(MMonCommand *m)
   bufferlist rdata;
   string rs;
   int r = -EINVAL;
+  rs = "unrecognized subsystem";
   if (!m->cmd.empty()) {
     if (m->cmd[0] == "mds") {
       mdsmon()->dispatch(m);
@@ -339,7 +340,10 @@ void Monitor::handle_command(MMonCommand *m)
       authmon()->dispatch(m);
       return;
     }
-    rs = "unrecognized subsystem";
+    if (m->cmd[0] == "health") {
+      monmon()->dispatch(m);
+      return;
+    }
   } else 
     rs = "no command";
 
index fab922be690d0f8c4f2d849c2d7391927758e8cc..4027449c0067d435b23ec1ab0a5e2010a8952c73 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "messages/MMonCommand.h"
 #include "common/Timer.h"
+#include "mon/MDSMonitor.h"
+#include "mon/OSDMonitor.h"
 
 #include <sstream>
 #include "config.h"
@@ -150,10 +152,30 @@ 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;
+    }
+    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;
     getline(ss, rs);
+
     mon->reply_command(m, r, rs, rdata, paxos->get_version());
     return true;
   } else
index ca57c96f475fab11213d6f94c779cf695f7d933c..5ab2d9555eebf137bce5c1a32d28a637cac00db7 100644 (file)
@@ -1016,7 +1016,27 @@ void OSDMonitor::mark_all_down()
   propose_pending();
 }
 
+enum health_status_t OSDMonitor::get_health(std::ostream &ss)
+{
+  enum health_status_t ret(HEALTH_OK);
+
+  int num_osds = osdmap.get_num_osds();
+  int num_up_osds = osdmap.get_num_up_osds();
+  int num_in_osds = osdmap.get_num_in_osds();
 
+  if (num_osds == 0) {
+    ss << " osdmonitor: no OSDS in osdmap!";
+    ret = HEALTH_ERR;
+  }
+  else if ((num_up_osds != num_osds) ||
+          (num_in_osds != num_osds)) {
+    ss << " osdmonitor: num_osds = " << num_osds << ", ";
+    ss << "num_up_osds = " << num_up_osds << ", num_in_osds = ";
+    ss << num_in_osds;
+    ret = HEALTH_WARN;
+  }
+  return ret;
+}
 
 bool OSDMonitor::preprocess_command(MMonCommand *m)
 {
index 9be1ab30750cae5b00b95caa67837baafab00293..193c209e9dc890207016af50f9254a60203025b6 100644 (file)
@@ -158,6 +158,7 @@ private:
 
   void tick();  // check state, take actions
 
+  enum health_status_t get_health(std::ostream &ss);
   bool preprocess_command(MMonCommand *m);
   bool prepare_command(MMonCommand *m);