From 09099c9e4c7d2aa31eb8a0b7c18e43272fae7ce2 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Mar 2014 07:03:01 -0800 Subject: [PATCH] osd: 'status' admin socket command Basic stuff, like what state is the OSD in, and what osdmap epoch are we on. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 18 +++++++++++++++++- src/osd/OSD.h | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 8d3e650248434..c4e91bdaeb5ee 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -988,7 +988,19 @@ bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format, Formatter *f = new_formatter(format); if (!f) f = new_formatter("json-pretty"); - if (command == "dump_ops_in_flight") { + if (command == "status") { + f->open_object_section("status"); + f->dump_stream("cluster_fsid") << superblock.cluster_fsid; + f->dump_stream("osd_fsid") << superblock.osd_fsid; + f->dump_unsigned("whoami", superblock.whoami); + f->dump_string("state", get_state_name(state)); + f->dump_unsigned("oldest_map", superblock.oldest_map); + f->dump_unsigned("newest_map", superblock.newest_map); + osd_lock.Lock(); + f->dump_unsigned("num_pgs", pg_map.size()); + osd_lock.Unlock(); + f->close_section(); + } else if (command == "dump_ops_in_flight") { op_tracker.dump_ops_in_flight(f); } else if (command == "dump_historic_ops") { op_tracker.dump_historic_ops(f); @@ -1273,6 +1285,9 @@ void OSD::final_init() int r; AdminSocket *admin_socket = cct->get_admin_socket(); asok_hook = new OSDSocketHook(this); + r = admin_socket->register_command("status", "status", asok_hook, + "high-level status of OSD"); + assert(r == 0); r = admin_socket->register_command("dump_ops_in_flight", "dump_ops_in_flight", asok_hook, "show the ops currently in flight"); @@ -1565,6 +1580,7 @@ int OSD::shutdown() } // unregister commands + cct->get_admin_socket()->unregister_command("status"); cct->get_admin_socket()->unregister_command("dump_ops_in_flight"); cct->get_admin_socket()->unregister_command("dump_historic_ops"); cct->get_admin_socket()->unregister_command("dump_op_pq_state"); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 29244cb5ead20..b371fb23aea3e 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -907,6 +907,17 @@ public: static const int STATE_STOPPING = 4; static const int STATE_WAITING_FOR_HEALTHY = 5; + static const char *get_state_name(int s) { + switch (s) { + case STATE_INITIALIZING: return "initializing"; + case STATE_BOOTING: return "booting"; + case STATE_ACTIVE: return "active"; + case STATE_STOPPING: return "stopping"; + case STATE_WAITING_FOR_HEALTHY: return "waiting_for_healthy"; + default: return "???"; + } + } + private: int state; epoch_t boot_epoch; // _first_ epoch we were marked up (after this process started) -- 2.39.5