From 39c229fcbdd7fb087f4ce1f13e83e2f1769873d1 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 15 May 2021 13:43:33 +0800 Subject: [PATCH] crimson/admin: print different metric type in different way and use registered_metric::operator() for better readability Signed-off-by: Kefu Chai --- src/crimson/admin/osd_admin.cc | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/crimson/admin/osd_admin.cc b/src/crimson/admin/osd_admin.cc index f21dad4075f..dd1f9e3be22 100644 --- a/src/crimson/admin/osd_admin.cc +++ b/src/crimson/admin/osd_admin.cc @@ -208,14 +208,57 @@ public: for (const auto& [full_name, metric_family]: seastar::scollectd::get_value_map()) { for (const auto& [labels, metric] : metric_family) { if (metric && metric->is_enabled()) { - auto& metric_function = metric->get_function(); - f->dump_float(metric->get_id().full_name(), metric_function().d()); + dump_metric_value(f.get(), full_name, *metric); } } } f->close_section(); return seastar::make_ready_future(std::move(f)); } +private: + using registered_metric = seastar::metrics::impl::registered_metric; + using data_type = seastar::metrics::impl::data_type; + + static void dump_metric_value(Formatter* f, + string_view full_name, + const registered_metric& metric) + { + switch (auto v = metric(); v.type()) { + case data_type::GAUGE: + f->dump_float(full_name, v.d()); + break; + case data_type::COUNTER: + [[fallthrough]]; + case data_type::DERIVE: + f->dump_unsigned(full_name, v.ui()); + break; + case data_type::HISTOGRAM: { + f->open_object_section(full_name); + auto&& h = v.get_histogram(); + f->dump_float("sum", h.sample_sum); + f->dump_unsigned("count", h.sample_count); + f->open_array_section("buckets"); + for (auto i : h.buckets) { + f->open_object_section("bucket"); + f->dump_float("le", i.upper_bound); + f->dump_unsigned("count", i.count); + f->close_section(); // "bucket" + } + { + f->open_object_section("bucket"); + f->dump_string("le", "+Inf"); + f->dump_unsigned("count", h.sample_count); + f->close_section(); + } + f->close_section(); // "buckets" + f->close_section(); // full_name + } + break; + default: + std::abort(); + break; + } + } }; template std::unique_ptr make_asok_hook(); -- 2.39.5