]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Modified num_bytes attribute in components_count to be a raw integer
authorBabu Shanmugam <anbu@enovance.com>
Mon, 10 Mar 2014 04:35:15 +0000 (04:35 +0000)
committerBabu Shanmugam <anbu@enovance.com>
Mon, 10 Mar 2014 04:35:15 +0000 (04:35 +0000)
Signed-off-by: Babu Shanmugam <anbu@enovance.com>
README.md
client/ceph-brag
server/ceph_brag/json.py
server/ceph_brag/model/db.py
server/sample.json

index f0224f505fe6432d36b0b1485f8392b48f28787b..6eabcf79c0b5a04dd5ec9d4ed3c2d450037bed1a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ Run 'ceph-brag -h' to get the usage information of this tool.
       "cluster_creation_date": "2014-01-16 13:38:41.928551",
       "uuid": "20679d0e-04b1-4004-8ee9-45ac271510e9",
       "components_count": {
-        "num_bytes": '0 bytes',
+        "num_bytes": 0,
         "num_osds": 1,
         "num_objects": 0,
         "num_pgs": 192,
index bec86da0a2c6b723418ef3b751f2fc442b0621f6..8bc2b4304e07998d98e544d1d9e985379b768795 100755 (executable)
@@ -52,6 +52,22 @@ def get_cluster_creation_date():
 
   return mo.group(2)
 
+def bytes_pretty_to_raw(byte_count, byte_scale):
+  if byte_scale == 'kB':
+    return byte_count >> 10
+  if byte_scale == 'MB':
+    return byte_count >> 20
+  if byte_scale == 'GB':
+    return byte_count >> 30
+  if byte_scale == 'TB':
+    return byte_count >> 40
+  if byte_scale == 'PB':
+    return byte_count >> 50
+  if byte_scale == 'EB':
+    return byte_count >> 60
+  
+  return byte_count
+
 def get_nums():
   (rc, o, e) = run_command(['ceph', '-s'])
   if rc is not 0:
@@ -87,7 +103,7 @@ def get_nums():
   else:
     num_pgs = int(mo.group(1))
     num_pools = int(mo.group(2))
-    byte_count = mo.group(3)
+    byte_count = int(mo.group(3))
     byte_scale = mo.group(4)
     num_objs = int(mo.group(5))
   nums = {'num_mons':num_mons,
@@ -95,7 +111,7 @@ def get_nums():
           'num_mdss':num_mdss,
           'num_pgs':num_pgs,
           'num_pools':num_pools,
-          'num_bytes': byte_count + " " + byte_scale,
+          'num_bytes': bytes_pretty_to_raw(byte_count, byte_scale),
           'num_objects':num_objs}
   return nums
 
index 57d106fa6a065dc87d353113414b43844dd955d9..bc4670287f2e85861074d02d6e327b537536944c 100644 (file)
@@ -22,7 +22,7 @@ def jsonify_cluster_info(ci):
 @jsonify.register(db.components_info)
 def jsonify_components_info(comps):
     return dict(
-            num_bytes=db.bytes_raw_to_pretty(comps.num_bytes),
+            num_bytes=comps.num_bytes,
             num_osds=comps.num_osds,
             num_objects=comps.num_objects,
             num_pgs=comps.num_pgs,
index 14c009aa3b57465e515d34beaa9f9630cc5bfac9..32f528a43c17f69401ce50e9b79c618313fc01e4 100644 (file)
@@ -1,6 +1,5 @@
 import json
 from datetime import datetime
-import re
 from sqlalchemy.orm import sessionmaker, scoped_session
 from sqlalchemy import Column, Integer, String, \
      DateTime, ForeignKey, BigInteger
@@ -139,46 +138,6 @@ class brag(object):
       self.pools = Session.query(pools_info).filter_by(vid=self.vi.index).all()
       self.sysinfo = sysinfo(self.vi.index)
 
-def bytes_pretty_to_raw(pretty):
-  mo = re.search("(\d+)\ (\S+)", pretty)
-  if not mo:
-    raise ValueError()
-
-  byte_count = int(mo.group(1))
-  byte_scale = mo.group(2)
-  if byte_scale == 'kB':
-    return byte_count >> 10
-  if byte_scale == 'MB':
-    return byte_count >> 20
-  if byte_scale == 'GB':
-    return byte_count >> 30
-  if byte_scale == 'TB':
-    return byte_count >> 40
-  if byte_scale == 'PB':
-    return byte_count >> 50
-  if byte_scale == 'EB':
-    return byte_count >> 60
-  
-  return byte_count
-
-def bytes_raw_to_pretty(num_bytes):
-  shift_limit = 100
-
-  if num_bytes > shift_limit << 60:
-    return str(num_bytes >> 60) + " EB"
-  if num_bytes > shift_limit << 50:
-    return str(num_bytes >> 50) + " PB"
-  if num_bytes > shift_limit << 40:
-    return str(num_bytes >> 40) + " TB"
-  if num_bytes > shift_limit << 30:
-    return str(num_bytes >> 30) + " GB"
-  if num_bytes > shift_limit << 20:
-    return str(num_bytes >> 20) + " MB"
-  if num_bytes > shift_limit << 10:
-    return str(num_bytes >> 10) + " kB"
-
-  return str(num_bytes) + " bytes"
-
 def put_new_version(data):
   info = json.loads(data)
   def add_cluster_info():
@@ -208,9 +167,8 @@ def put_new_version(data):
 
   def add_components_info(vi):
     comps_count= info['components_count']
-    nbytes = comps_count['num_bytes']
     comps_info = components_info(vid=vi.index,
-                         num_bytes=bytes_pretty_to_raw(nbytes),
+                         num_bytes=comps_count['num_bytes'],
                          num_osds=comps_count['num_osds'],
                          num_objects=comps_count['num_objects'],
                          num_pgs=comps_count['num_pgs'],
index 61d9534282fdf5820be4733eba13704d90049c4e..4915f5afd3f886675734e4fe291ac1e6e2c7ad13 100644 (file)
@@ -5,7 +5,7 @@
     "num_pgs": 192,
     "num_mdss": 1,
     "num_osds": 1,
-    "num_bytes": "0 bytes",
+    "num_bytes": 0,
     "num_pools": 3,
     "num_mons": 1,
     "num_objects": 0