From: Boris Ranto Date: Mon, 30 Apr 2018 23:12:02 +0000 (+0200) Subject: prometheus: Handle the TIME perf counter type metrics X-Git-Tag: v13.1.0~24^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=056bc08d51306f4e4d031d1e3ff68ad7312c55d8;p=ceph.git prometheus: Handle the TIME perf counter type metrics This patch correctly sets the PERFCOUNTER_MASK to 3 so that the PERFCOUNTER_TIME metrics are not ignored by the mgr_module code. It also converts the TIME metrics from nanoseconds to seconds just like the ceph perf dump does and exposes the metrics via prometheus module. Signed-off-by: Boris Ranto --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index b51952ebd18e0..ea79771fbabe6 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -229,7 +229,7 @@ class MgrModule(ceph_module.BaseMgrModule): PERFCOUNTER_LONGRUNAVG = 4 PERFCOUNTER_COUNTER = 8 PERFCOUNTER_HISTOGRAM = 0x10 - PERFCOUNTER_TYPE_MASK = ~2 + PERFCOUNTER_TYPE_MASK = ~3 # units supported BYTES = 0 @@ -337,6 +337,13 @@ class MgrModule(ceph_module.BaseMgrModule): return '' + def _perfvalue_to_value(self, stattype, value): + if stattype & self.PERFCOUNTER_TIME: + # Convert from ns to seconds + return value / 1000000000.0 + else: + return value + def _unit_to_str(self, unit): if unit == self.NONE: return "/s" diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index c7daa128dd8af..dea9b59717880 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -554,7 +554,8 @@ class Module(MgrModule): ("ceph_daemon",), )) - self.metrics.append(path, counter_info['value'], (daemon,)) + value = self._perfvalue_to_value(counter_info['type'], counter_info['value']) + self.metrics.append(path, value, (daemon,)) # It is sufficient to reset the pending metrics once per scrape self.metrics.reset()