]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: fix health monitor calls
authorSage Weil <sage@inktank.com>
Fri, 19 Apr 2013 19:16:11 +0000 (12:16 -0700)
committerSage Weil <sage@inktank.com>
Fri, 19 Apr 2013 19:16:11 +0000 (12:16 -0700)
- unconditionally call get_health, regardless of formatter *
- return a meaningful health status code

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/DataHealthService.cc
src/mon/HealthMonitor.cc
src/mon/Monitor.cc

index d1a227fe0fd66e657cb28012157adc402f100ee5..949e1e2efe3f2c0fbd543dce790dfb033e0d74c0 100644 (file)
@@ -59,10 +59,10 @@ health_status_t DataHealthService::get_health(
     list<pair<health_status_t,string> > *detail)
 {
   dout(10) << __func__ << dendl;
-  assert(f != NULL);
-
-  f->open_object_section("data_health");
-  f->open_array_section("mons");
+  if (f) {
+    f->open_object_section("data_health");
+    f->open_array_section("mons");
+  }
 
   health_status_t overall_status = HEALTH_OK;
 
@@ -92,21 +92,25 @@ health_status_t DataHealthService::get_health(
       detail->push_back(make_pair(health_status, ss.str()));
     }
 
-    f->open_object_section(mon_name.c_str());
-    f->dump_string("name", mon_name.c_str());
-    f->dump_int("kb_total", stats.kb_total);
-    f->dump_int("kb_used", stats.kb_used);
-    f->dump_int("kb_avail", stats.kb_avail);
-    f->dump_int("avail_percent", stats.latest_avail_percent);
-    f->dump_stream("last_updated") << stats.last_update;
-    f->dump_stream("health") << health_status;
-    if (health_status != HEALTH_OK)
-      f->dump_string("health_detail", health_detail);
-    f->close_section();
+    if (f) {
+      f->open_object_section(mon_name.c_str());
+      f->dump_string("name", mon_name.c_str());
+      f->dump_int("kb_total", stats.kb_total);
+      f->dump_int("kb_used", stats.kb_used);
+      f->dump_int("kb_avail", stats.kb_avail);
+      f->dump_int("avail_percent", stats.latest_avail_percent);
+      f->dump_stream("last_updated") << stats.last_update;
+      f->dump_stream("health") << health_status;
+      if (health_status != HEALTH_OK)
+       f->dump_string("health_detail", health_detail);
+      f->close_section();
+    }
+  }
+  
+  if (f) {
+    f->close_section(); // mons
+    f->close_section(); // data_health
   }
-
-  f->close_section(); // mons
-  f->close_section(); // data_health
 
   return overall_status;
 }
index b62ed7da31ec4b8e5cd7b7ff61b9bca94d4f9271..6239d32a873056b7b70399bb87a8671d4b317613 100644 (file)
@@ -79,17 +79,26 @@ void HealthMonitor::service_shutdown()
 }
 
 health_status_t HealthMonitor::get_health(Formatter *f,
-                               list<pair<health_status_t,string> > *detail) {
-  assert(f != NULL);
-  f->open_object_section("health");
-  f->open_array_section("health_services");
+                                         list<pair<health_status_t,string> > *detail)
+{
+  health_status_t overall = HEALTH_OK;
+  if (f) {
+    f->open_object_section("health");
+    f->open_array_section("health_services");
+  }
 
   for (map<int,HealthServiceRef>::iterator it = services.begin();
        it != services.end(); ++it) {
-    it->second->get_health(f, detail);
+    health_status_t h = it->second->get_health(f, detail);
+    if (overall > h)
+      overall = h;
+  }
+
+  if (f) {
+    f->close_section(); // health_services
+    f->close_section(); // health
   }
 
-  f->close_section(); // health_services
-  f->close_section(); // health
+  return overall;
 }
 
index da6a7e662bd775c39316d4ad36a0b3df36a065f7..c13773be817e59a32aa348f39e908a0b6f74e0d6 100644 (file)
@@ -2297,12 +2297,9 @@ void Monitor::get_health(string& status, bufferlist *detailbl, Formatter *f)
   if (f)
     f->close_section();
 
-  if (f) {
-    health_status_t hmstatus =
-      health_monitor->get_health(f, (detailbl ? &detail : NULL));
-    if (overall > hmstatus)
-      overall = hmstatus;
-  }
+  health_status_t hmstatus = health_monitor->get_health(f, (detailbl ? &detail : NULL));
+  if (overall > hmstatus)
+    overall = hmstatus;
 
   stringstream fss;
   fss << overall;