Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 267e60e2d59ae8cd4894a4cc367e703540b3de0c Mon Sep 17 00:00:00 2001
- From: Boris Ranto <branto@redhat.com>
- Date: Wed, 21 Nov 2018 23:01:57 +0100
- Subject: [PATCH 2/2] pybind/mgr/mgr_module: Add get_data_health()
- This function reports the state of data health in ceph cluster based on
- PG health checks.
- Signed-off-by: Boris Ranto <branto@redhat.com>
- ---
- src/pybind/mgr/mgr_module.py | 34 ++++++++++++++++++++++++++++++++++
- 1 file changed, 34 insertions(+)
- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py
- index 3c9510fbda..7158efb380 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
- import rados
- +import json
- PG_STATES = [
- "active",
- @@ -923,3 +924,36 @@ class MgrModule(ceph_module.BaseMgrModule):
- :param int query_id: query ID
- """
- return self._ceph_remove_osd_perf_query(query_id)
- +
- + def get_data_health(self):
- + state_map = {
- + 'PG_AVAILABILITY': 'Unavailable',
- + 'PG_DEGRADED': 'Degraded',
- + 'PG_DEGRADED_FULL': 'Degraded full',
- + 'PG_DAMAGED': 'Damaged',
- + }
- +
- + # Get the data from mgr
- + total_pgs = self.get('pg_status')['num_pgs'] # total number of PGs
- + health_checks = json.loads(self.get('health')['json'])['checks']
- +
- + # Build the map of pg IDs and their health state
- + # We need to do this since a single PG can be in various health
- + # states but we only care about the worst state it is in
- + health_state = {}
- + # Iterate in fixed order, we want DAMAGED to overwrite DEGRADED, etc
- + for state in ['PG_AVAILABILITY', 'PG_DEGRADED', 'PG_DEGRADED_FULL', 'PG_DAMAGED']:
- + if health_checks.has_key(state):
- + # The first detail message contains the list of PGs
- + pgs = health_checks[state]['detail'][0]['message'].split(',')
- + for _id in pgs:
- + health_state[_id] = state_map[state]
- +
- + # Count the number of occurrences of each health state and return
- + data_health = dict.fromkeys(state_map.values(), 0)
- + data_health['HEALTHY'] = total_pgs - len(health_state)
- +
- + for _val in health_state.values():
- + data_health[_val] += 1
- +
- + return data_health
- --
- 2.19.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement