]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: fix format for rbd-mirror prometheus metrics
authorMykola Golub <mgolub@suse.com>
Tue, 21 May 2019 16:26:15 +0000 (17:26 +0100)
committerMykola Golub <mgolub@suse.com>
Tue, 11 Jun 2019 07:27:15 +0000 (10:27 +0300)
Fixes: https://tracker.ceph.com/issues/39977
Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit 425f97ea990e4e5ea5853c8b462641112eef871d)

src/pybind/mgr/mgr_module.py
src/pybind/mgr/prometheus/module.py

index 1fda163ba38514bf6f50093491bf38fe2559d04c..b6228462fccfd95bd6ddace54a33db4fff0ec133 100644 (file)
@@ -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
index 0f95331f587e75a8ad82520b9dfc7d6b06b74d52..d3ea3d48a1be0222290b866dc5079f2912180dce 100644 (file)
@@ -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()