]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd: introduce dump_osd_pg_stats admin socket command.
authorIgor Fedotov <igor.fedotov@croit.io>
Wed, 20 Sep 2023 16:10:59 +0000 (19:10 +0300)
committerIgor Fedotov <igor.fedotov@croit.io>
Wed, 4 Oct 2023 11:37:29 +0000 (14:37 +0300)
One can learn full OSD stats in a way they're reported to monitors using it.

Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/messages/MPGStats.h
src/osd/OSD.cc

index 65cec5244788998bd6885a2d7d1adf68902e96c7..2d9c2dcb5c2c5784a391539abd7758405fff8fbb 100644 (file)
@@ -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;
index 52f937d7ff4d5d886f5e682f7bcb8c06a2c8f2a3..6b3dd52786a3cbe1794804300d059fd838f46580 100644 (file)
@@ -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