]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common: dump metric with labels
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 23 Jun 2021 07:36:27 +0000 (15:36 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Thu, 8 Jul 2021 13:08:02 +0000 (21:08 +0800)
Otherwise we cannot distinguish metrics of the same name.
Labels also contain useful information about the metric.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/admin/osd_admin.cc

index e1c8c5b4d8ab4a661154eaa96f87b6a405244ed1..5c4ffdd2a7e3c03d0fa0a05ae64e1c17503dcb53 100644 (file)
@@ -218,7 +218,7 @@ public:
       }
       for (const auto& [labels, metric] : metric_family) {
         if (metric && metric->is_enabled()) {
-          dump_metric_value(f.get(), full_name, *metric);
+          dump_metric_value(f.get(), full_name, *metric, labels);
         }
       }
     }
@@ -231,20 +231,26 @@ private:
 
   static void dump_metric_value(Formatter* f,
                                 string_view full_name,
-                                const registered_metric& metric)
+                                const registered_metric& metric,
+                                const seastar::metrics::impl::labels_type& labels)
   {
+    f->open_object_section(full_name);
+    for (const auto& [key, value] : labels) {
+      f->dump_string(key, value);
+    }
+    auto value_name = "value";
     switch (auto v = metric(); v.type()) {
     case data_type::GAUGE:
-      f->dump_float(full_name, v.d());
+      f->dump_float(value_name, v.d());
       break;
     case data_type::COUNTER:
-      f->dump_unsigned(full_name, v.ui());
+      f->dump_unsigned(value_name, v.ui());
       break;
     case data_type::DERIVE:
-      f->dump_int(full_name, v.i());
+      f->dump_int(value_name, v.i());
       break;
     case data_type::HISTOGRAM: {
-      f->open_object_section(full_name);
+      f->open_object_section(value_name);
       auto&& h = v.get_histogram();
       f->dump_float("sum", h.sample_sum);
       f->dump_unsigned("count", h.sample_count);
@@ -262,13 +268,14 @@ private:
         f->close_section();
       }
       f->close_section(); // "buckets"
-      f->close_section(); // full_name
+      f->close_section(); // value_name
     }
       break;
     default:
       std::abort();
       break;
     }
+    f->close_section(); // full_name
   }
 };
 template std::unique_ptr<AdminSocketHook> make_asok_hook<DumpMetricsHook>();