]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: ceph_pg_* metrics contains last value instead of sum all of them 34163/head
authorJacek Suchenia <jacek.suchenia@gmail.com>
Sat, 14 Mar 2020 13:12:10 +0000 (14:12 +0100)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Wed, 25 Mar 2020 02:54:38 +0000 (09:54 +0700)
During evaluation of pool stats metrics contains last reported value instead of sum

Fixes: https://tracker.ceph.com/issues/44590
Signed-off-by: Jacek Suchenia <jacek.suchenia@gmail.com>
(cherry picked from commit ad4d790a35af483f3a240f247cda5754301a9199)

src/pybind/mgr/prometheus/module.py

index 2f591b20b81233230670eee8b6f51b1479ce8782..fa6073bd3cbd883cb163492289b76ee14effdf93 100644 (file)
@@ -486,13 +486,13 @@ class Module(MgrModule):
                 ceph_release = host_version[1].split()[-2] # e.g. nautilus
             else:
                 _state = 0
-            
+
             self.metrics['mgr_metadata'].set(1, (
                 'mgr.{}'.format(mgr), host_version[0],
                 host_version[1]
             ))
             self.metrics['mgr_status'].set(_state, (
-                'mgr.{}'.format(mgr), 
+                'mgr.{}'.format(mgr),
             ))
         always_on_modules = mgr_map['always_on_modules'].get(ceph_release, [])
         active_modules = list(always_on_modules)
@@ -516,30 +516,19 @@ class Module(MgrModule):
         pg_summary = self.get('pg_summary')
 
         for pool in pg_summary['by_pool']:
-            total = 0
-            for state_name, count in pg_summary['by_pool'][pool].items():
-                reported_states = {}
+            num_by_state = dict((state, 0) for state in PG_STATES)
+            num_by_state['total'] = 0
 
+            for state_name, count in pg_summary['by_pool'][pool].items():
                 for state in state_name.split('+'):
-                    reported_states[state] = reported_states.get(
-                        state, 0) + count
-
-                for state in reported_states:
-                    path = 'pg_{}'.format(state)
-                    try:
-                        self.metrics[path].set(reported_states[state],(pool,))
-                    except KeyError:
-                        self.log.warn("skipping pg in unknown state {}".format(state))
-
-                for state in PG_STATES:
-                    if state not in reported_states:
-                        try:
-                            self.metrics['pg_{}'.format(state)].set(0,(pool,))
-                        except KeyError:
-                            self.log.warn(
-                                "skipping pg in unknown state {}".format(state))
-                total = total + count
-            self.metrics['pg_total'].set(total,(pool,))
+                    num_by_state[state] += count
+                num_by_state['total'] += count
+
+            for state, num in num_by_state.items():
+                try:
+                    self.metrics["pg_{}".format(state)].set(num, (pool,))
+                except KeyError:
+                    self.log.warn("skipping pg in unknown state {}".format(state))
 
     def get_osd_stats(self):
         osd_stats = self.get('osd_stats')