From: Sage Weil Date: Fri, 19 Apr 2013 19:16:11 +0000 (-0700) Subject: mon: fix health monitor calls X-Git-Tag: v0.61~140^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aa0d5f39d62a53002bbde673d6972b1dac86d968;p=ceph.git mon: fix health monitor calls - unconditionally call get_health, regardless of formatter * - return a meaningful health status code Signed-off-by: Sage Weil --- diff --git a/src/mon/DataHealthService.cc b/src/mon/DataHealthService.cc index d1a227fe0fd6..949e1e2efe3f 100644 --- a/src/mon/DataHealthService.cc +++ b/src/mon/DataHealthService.cc @@ -59,10 +59,10 @@ health_status_t DataHealthService::get_health( list > *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; } diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index b62ed7da31ec..6239d32a8730 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -79,17 +79,26 @@ void HealthMonitor::service_shutdown() } health_status_t HealthMonitor::get_health(Formatter *f, - list > *detail) { - assert(f != NULL); - f->open_object_section("health"); - f->open_array_section("health_services"); + list > *detail) +{ + health_status_t overall = HEALTH_OK; + if (f) { + f->open_object_section("health"); + f->open_array_section("health_services"); + } for (map::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; } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index da6a7e662bd7..c13773be817e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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;