From 0b8b98907c7f60cfe64636c3278e474bd03f27ce Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Wed, 20 Sep 2023 19:10:59 +0300 Subject: [PATCH] osd: introduce dump_osd_pg_stats admin socket command. One can learn full OSD stats in a way they're reported to monitors using it. Signed-off-by: Igor Fedotov --- src/messages/MPGStats.h | 25 +++++++++++++++++++++++++ src/osd/OSD.cc | 12 ++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/messages/MPGStats.h b/src/messages/MPGStats.h index 65cec524478..2d9c2dcb5c2 100644 --- a/src/messages/MPGStats.h +++ b/src/messages/MPGStats.h @@ -44,6 +44,31 @@ public: void print(std::ostream& out) const override { out << "pg_stats(" << pg_stat.size() << " pgs seq " << osd_stat.seq << " v " << version << ")"; } + void dump_stats(ceph::Formatter *f) const { + f->open_object_section("stats"); + { + f->open_array_section("pg_stat"); + for(const auto& [_pg, _stat] : pg_stat) { + f->open_object_section("pg_stat"); + _pg.dump(f); + _stat.dump(f); + f->close_section(); + } + f->close_section(); + + f->dump_object("osd_stat", osd_stat); + + f->open_array_section("pool_stat"); + for(const auto& [_id, _stat] : pool_stat) { + f->open_object_section("pool"); + f->dump_int("poolid", _id); + _stat.dump(f); + f->close_section(); + } + f->close_section(); + } + f->close_section(); + } void encode_payload(uint64_t features) override { using ceph::encode; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 52f937d7ff4..6b3dd52786a 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3278,6 +3278,13 @@ will start to track new ops received afterwards."; st.dump(f); f->close_section(); } + } else if (prefix == "dump_osd_pg_stats") { + lock_guard l(osd_lock); + + MPGStats* m = collect_pg_stats(); + ceph_assert(m); + m->dump_stats(f); + m->put(); } else { ceph_abort_msg("broken asok registration"); } @@ -4155,6 +4162,11 @@ void OSD::final_init() "Dump store's statistics for the given pool"); ceph_assert(r == 0); + r = admin_socket->register_command( + "dump_osd_pg_stats ", asok_hook, + "Dump OSD PGs' statistics"); + ceph_assert(r == 0); + test_ops_hook = new TestOpsSocketHook(&(this->service), this->store.get()); // Note: pools are CephString instead of CephPoolname because // these commands traditionally support both pool names and numbers -- 2.39.5