SHARE
TWEET

Untitled

a guest Nov 22nd, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 267e60e2d59ae8cd4894a4cc367e703540b3de0c Mon Sep 17 00:00:00 2001
  2. From: Boris Ranto <branto@redhat.com>
  3. Date: Wed, 21 Nov 2018 23:01:57 +0100
  4. Subject: [PATCH 2/2] pybind/mgr/mgr_module: Add get_data_health()
  5.  
  6. This function reports the state of data health in ceph cluster based on
  7. PG health checks.
  8.  
  9. Signed-off-by: Boris Ranto <branto@redhat.com>
  10. ---
  11.  src/pybind/mgr/mgr_module.py | 34 ++++++++++++++++++++++++++++++++++
  12.  1 file changed, 34 insertions(+)
  13.  
  14. diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py
  15. index 3c9510fbda..7158efb380 100644
  16. --- a/src/pybind/mgr/mgr_module.py
  17. +++ b/src/pybind/mgr/mgr_module.py
  18. @@ -6,6 +6,7 @@ import six
  19.  import threading
  20.  from collections import defaultdict
  21.  import rados
  22. +import json
  23.  
  24.  PG_STATES = [
  25.          "active",
  26. @@ -923,3 +924,36 @@ class MgrModule(ceph_module.BaseMgrModule):
  27.          :param int query_id: query ID
  28.          """
  29.          return self._ceph_remove_osd_perf_query(query_id)
  30. +
  31. +    def get_data_health(self):
  32. +        state_map = {
  33. +            'PG_AVAILABILITY': 'Unavailable',
  34. +            'PG_DEGRADED': 'Degraded',
  35. +            'PG_DEGRADED_FULL': 'Degraded full',
  36. +            'PG_DAMAGED': 'Damaged',
  37. +        }
  38. +
  39. +        # Get the data from mgr
  40. +        total_pgs = self.get('pg_status')['num_pgs'] # total number of PGs
  41. +        health_checks = json.loads(self.get('health')['json'])['checks']
  42. +
  43. +        # Build the map of pg IDs and their health state
  44. +        # We need to do this since a single PG can be in various health
  45. +        # states but we only care about the worst state it is in
  46. +        health_state = {}
  47. +        # Iterate in fixed order, we want DAMAGED to overwrite DEGRADED, etc
  48. +        for state in ['PG_AVAILABILITY', 'PG_DEGRADED', 'PG_DEGRADED_FULL', 'PG_DAMAGED']:
  49. +            if health_checks.has_key(state):
  50. +                # The first detail message contains the list of PGs
  51. +                pgs = health_checks[state]['detail'][0]['message'].split(',')
  52. +                for _id in pgs:
  53. +                    health_state[_id] = state_map[state]
  54. +
  55. +        # Count the number of occurrences of each health state and return
  56. +        data_health = dict.fromkeys(state_map.values(), 0)
  57. +        data_health['HEALTHY'] = total_pgs - len(health_state)
  58. +
  59. +        for _val in health_state.values():
  60. +            data_health[_val] += 1
  61. +
  62. +        return data_health
  63. --
  64. 2.19.1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top