From 70640bf185eb268f25fd45c5c8080bed81255bae Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 23 Apr 2011 15:07:32 -0700 Subject: [PATCH] mon: generalize health check a bit Any PaxosService can return a status (or not). Signed-off-by: Sage Weil --- src/mon/Monitor.cc | 24 ++++++++++++++++++++++-- src/mon/MonmapMonitor.cc | 22 ---------------------- src/mon/PaxosService.h | 2 ++ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 543530c49b650..a342445bd728f 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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::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"; diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 46267b43c4230..39f9cc84c8020 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -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; diff --git a/src/mon/PaxosService.h b/src/mon/PaxosService.h index 18570a3327ba5..8d903b7f25581 100644 --- a/src/mon/PaxosService.h +++ b/src/mon/PaxosService.h @@ -171,6 +171,8 @@ public: virtual void init() {} + virtual enum health_status_t get_health(std::ostream& os) const { return HEALTH_OK; } + }; #endif -- 2.39.5