From: Mykola Golub Date: Tue, 21 May 2019 16:26:15 +0000 (+0100) Subject: pybind/mgr: fix format for rbd-mirror prometheus metrics X-Git-Tag: v14.2.2~53^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=aebe1b58fe051cc4c23ff167f64491153e4e110b;p=ceph.git pybind/mgr: fix format for rbd-mirror prometheus metrics Fixes: https://tracker.ceph.com/issues/39977 Signed-off-by: Mykola Golub (cherry picked from commit 425f97ea990e4e5ea5853c8b462641112eef871d) --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 1fda163ba3851..b6228462fccfd 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -6,6 +6,7 @@ import six import threading from collections import defaultdict, namedtuple import rados +import re import time PG_STATES = [ @@ -658,6 +659,25 @@ class MgrModule(ceph_module.BaseMgrModule): return '' + def _perfpath_to_path_labels(self, daemon, path): + label_names = ("ceph_daemon",) + labels = (daemon,) + + if daemon.startswith('rbd-mirror.'): + match = re.match( + r'^rbd_mirror_([^/]+)/(?:(?:([^/]+)/)?)(.*)\.(replay(?:_bytes|_latency)?)$', + path + ) + if match: + path = 'rbd_mirror_' + match.group(4) + pool = match.group(1) + namespace = match.group(2) or '' + image = match.group(3) + label_names += ('pool', 'namespace', 'image') + labels += (pool, namespace, image) + + return path, label_names, labels, + def _perfvalue_to_value(self, stattype, value): if stattype & self.PERFCOUNTER_TIME: # Convert from ns to seconds diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 0f95331f587e7..d3ea3d48a1be0 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -852,6 +852,9 @@ class Module(MgrModule): self.log.debug('ignoring %s, type %s' % (path, stattype)) continue + path, label_names, labels = self._perfpath_to_path_labels( + daemon, path) + # Get the value of the counter value = self._perfvalue_to_value( counter_info['type'], counter_info['value']) @@ -864,9 +867,9 @@ class Module(MgrModule): stattype, _path, counter_info['description'] + ' Total', - ("ceph_daemon",), + label_names, ) - self.metrics[_path].set(value, (daemon,)) + self.metrics[_path].set(value, labels) _path = path + '_count' if _path not in self.metrics: @@ -874,18 +877,18 @@ class Module(MgrModule): 'counter', _path, counter_info['description'] + ' Count', - ("ceph_daemon",), + label_names, ) - self.metrics[_path].set(counter_info['count'], (daemon,)) + self.metrics[_path].set(counter_info['count'], labels,) else: if path not in self.metrics: self.metrics[path] = Metric( stattype, path, counter_info['description'], - ("ceph_daemon",), + label_names, ) - self.metrics[path].set(value, (daemon,)) + self.metrics[path].set(value, labels) self.get_rbd_stats()