]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/prometheus: Fix pg_* counts
authorBoris Ranto <branto@redhat.com>
Fri, 16 Feb 2018 17:45:58 +0000 (18:45 +0100)
committerBoris Ranto <branto@redhat.com>
Mon, 19 Feb 2018 16:30:46 +0000 (17:30 +0100)
Currently, the pg_* counts are not computed properly. We split the
current state by '+' sign but do not add the pg count to the already
found pg count. Instead, we overwrite any existing pg count with the new
count. This patch fixes it by adding all the pg counts together for all
the states.

It also introduces a new pg_total metric for pg_total that shows the
total count of PGs.

Signed-off-by: Boris Ranto <branto@redhat.com>
src/pybind/mgr/prometheus/module.py

index fec46138ae9c758af69c9928844d9869185aaf09..55cc1a8c7a2d3e75565abdd59bd7e23ef531cbc8 100644 (file)
@@ -179,6 +179,13 @@ class Module(MgrModule):
             'POOL Metadata',
             POOL_METADATA
         )
+
+        metrics['pg_total'] = Metric(
+            'gauge',
+            'pg_total',
+            'PG Total Count'
+        )
+
         for state in OSD_STATUS:
             path = 'osd_{}'.format(state)
             self.log.debug("init: creating {}".format(path))
@@ -249,16 +256,25 @@ class Module(MgrModule):
 
     def get_pg_status(self):
         # TODO add per pool status?
-        pg_s = self.get('pg_summary')['all']
-        reported_pg_s = [(s,v) for key, v in pg_s.items() for s in
-                         key.split('+')]
-        for state, value in reported_pg_s:
+        pg_status = self.get('pg_status')
+
+        # Set total count of PGs, first
+        self.metrics['pg_total'].set(
+            pg_status['num_pgs'],
+        )
+
+        reported_states = {}
+        for pg in pg_status['pgs_by_state']:
+            for state in pg['state_name'].split('+'):
+                reported_states[state] =  reported_states.get(state, 0) + pg['count']
+
+        for state in reported_states:
             path = 'pg_{}'.format(state)
             try:
-                self.metrics[path].set(value)
+                self.metrics[path].set(reported_states[state])
             except KeyError:
                 self.log.warn("skipping pg in unknown state {}".format(state))
-        reported_states = [s[0] for s in reported_pg_s]
+
         for state in PG_STATES:
             path = 'pg_{}'.format(state)
             if state not in reported_states: