<< ((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
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)
{
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);
bufferlist rdata;
string rs;
int r = -EINVAL;
+ rs = "unrecognized subsystem";
if (!m->cmd.empty()) {
if (m->cmd[0] == "mds") {
mdsmon()->dispatch(m);
authmon()->dispatch(m);
return;
}
- rs = "unrecognized subsystem";
+ if (m->cmd[0] == "health") {
+ monmon()->dispatch(m);
+ return;
+ }
} else
rs = "no command";
#include "messages/MMonCommand.h"
#include "common/Timer.h"
+#include "mon/MDSMonitor.h"
+#include "mon/OSDMonitor.h"
#include <sstream>
#include "config.h"
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
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)
{
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);