Skip to content

Commit

Permalink
mgr: ceph_pg_* metrics contains last value instead of sum all of them
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jsuchenia authored and tchaikov committed Mar 23, 2020
1 parent e2f3e60 commit ad4d790
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/pybind/mgr/prometheus/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ def get_mgr_status(self):
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)
Expand All @@ -516,30 +516,19 @@ def get_pg_status(self):
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')
Expand Down

0 comments on commit ad4d790

Please sign in to comment.