]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: New Landing Page 23568/head
authoralfonsomthd <almartin@redhat.com>
Wed, 19 Sep 2018 16:25:24 +0000 (18:25 +0200)
committeralfonsomthd <almartin@redhat.com>
Wed, 19 Sep 2018 16:25:24 +0000 (18:25 +0200)
get_client_perf method refactored for readability.

Fixes: https://tracker.ceph.com/issues/24573
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
src/pybind/mgr/dashboard/services/ceph_service.py

index 6fc0d908f165aff68420a99db7728b10c0bd7524..91b4f351ef6e7cd7d081753b18cfad05f5c265bc 100644 (file)
@@ -34,14 +34,6 @@ class CephService(object):
     OSD_FLAG_NO_SCRUB = 'noscrub'
     OSD_FLAG_NO_DEEP_SCRUB = 'nodeep-scrub'
 
-    POOL_STAT_CLIENT_IO_RATE = 'client_io_rate'
-    POOL_STAT_READ_BYTES_PER_SEC = 'read_bytes_sec'
-    POOL_STAT_READ_OP_PER_SEC = 'read_op_per_sec'
-    POOL_STAT_RECOVERY_BYTES_PER_SEC = 'recovering_bytes_per_sec'
-    POOL_STAT_RECOVERY_RATE = 'recovery_rate'
-    POOL_STAT_WRITE_BYTES_PER_SEC = 'write_bytes_sec'
-    POOL_STAT_WRITE_OP_PER_SEC = 'write_op_per_sec'
-
     PG_STATUS_SCRUBBING = 'scrubbing'
     PG_STATUS_DEEP_SCRUBBING = 'deep'
 
@@ -212,33 +204,27 @@ class CephService(object):
     def get_client_perf(cls):
         pools_stats = mgr.get('osd_pool_stats')['pool_stats']
 
-        client_perf = {
-            cls.POOL_STAT_READ_BYTES_PER_SEC: 0,
-            cls.POOL_STAT_READ_OP_PER_SEC: 0,
-            cls.POOL_STAT_RECOVERY_BYTES_PER_SEC: 0,
-            cls.POOL_STAT_WRITE_BYTES_PER_SEC: 0,
-            cls.POOL_STAT_WRITE_OP_PER_SEC: 0,
+        io_stats = {
+            'read_bytes_sec': 0,
+            'read_op_per_sec': 0,
+            'write_bytes_sec': 0,
+            'write_op_per_sec': 0,
         }
+        recovery_stats = {'recovering_bytes_per_sec': 0}
 
         for pool_stats in pools_stats:
-            client_io = pool_stats[cls.POOL_STAT_CLIENT_IO_RATE]
-            if cls.POOL_STAT_READ_BYTES_PER_SEC in client_io:
-                client_perf[cls.POOL_STAT_READ_BYTES_PER_SEC] +=\
-                    client_io[cls.POOL_STAT_READ_BYTES_PER_SEC]
-            if cls.POOL_STAT_READ_OP_PER_SEC in client_io:
-                client_perf[cls.POOL_STAT_READ_OP_PER_SEC] +=\
-                    client_io[cls.POOL_STAT_READ_OP_PER_SEC]
-            if cls.POOL_STAT_WRITE_BYTES_PER_SEC in client_io:
-                client_perf[cls.POOL_STAT_WRITE_BYTES_PER_SEC] +=\
-                    client_io[cls.POOL_STAT_WRITE_BYTES_PER_SEC]
-            if cls.POOL_STAT_WRITE_OP_PER_SEC in client_io:
-                client_perf[cls.POOL_STAT_WRITE_OP_PER_SEC] +=\
-                    client_io[cls.POOL_STAT_WRITE_OP_PER_SEC]
-
-            client_recovery = pool_stats[cls.POOL_STAT_RECOVERY_RATE]
-            if cls.POOL_STAT_RECOVERY_BYTES_PER_SEC in client_recovery:
-                client_perf[cls.POOL_STAT_RECOVERY_BYTES_PER_SEC] +=\
-                    client_recovery[cls.POOL_STAT_RECOVERY_BYTES_PER_SEC]
+            client_io = pool_stats['client_io_rate']
+            for stat in list(io_stats.keys()):
+                if stat in client_io:
+                    io_stats[stat] += client_io[stat]
+
+            client_recovery = pool_stats['recovery_rate']
+            for stat in list(recovery_stats.keys()):
+                if stat in client_recovery:
+                    recovery_stats[stat] += client_recovery[stat]
+
+        client_perf = io_stats.copy()
+        client_perf.update(recovery_stats)
 
         return client_perf