]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Removed all regular expression parsing and used '-f json' instead
authorBabu Shanmugam <anbu@enovance.com>
Mon, 10 Mar 2014 06:11:03 +0000 (06:11 +0000)
committerBabu Shanmugam <anbu@enovance.com>
Mon, 10 Mar 2014 06:11:03 +0000 (06:11 +0000)
Signed-off-by: Babu Shanmugam <anbu@enovance.com>
README.md
client/ceph-brag
server/ceph_brag/model/db.py
server/sample.json

index 6eabcf79c0b5a04dd5ec9d4ed3c2d450037bed1a..55af44f83a6a394de2cd396306ca2192b890181c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -59,18 +59,18 @@ Run 'ceph-brag -h' to get the usage information of this tool.
       "pool_metadata": [
         {
           "size": 3,
-          "id": "0",
-          "type": "replicated"
+          "id": 0,
+          "type": 1
         },
         {
           "size": 3,
-          "id": "1",
-          "name": "erasure"
+          "id": 1,
+          "type": 1
         },
         {
           "size": 3,
-          "id": "2",
-          "name": "replicated"
+          "id": 2,
+          "name": 1
         }
       ],
       "sysinfo": {
index 8bc2b4304e07998d98e544d1d9e985379b768795..e07ad01b6635c0d55961f0812f895a6195dc380b 100755 (executable)
@@ -31,26 +31,12 @@ def get_uuid():
   return uid
 
 def get_cluster_creation_date():
-  (rc, o, e) = run_command(['ceph', 'mon', 'dump'])
+  (rc, o, e) = run_command(['ceph', 'mon', 'dump', '-f', 'json'])
   if rc is not 0:
     raise RuntimeError("\'ceph mon dump\' failed - " + e)
 
-  rec = re.compile('(.*created\ )(.*)(\n.*)')
-
-  mo = rec.search(o);
-  if mo and mo.group(2) != '0.000000':
-    return mo.group(2)
-
-  # Try and get the date from osd dump
-  (rc, o, e) = run_command(['ceph', 'osd', 'dump'])
-  if rc is not 0:
-    raise RuntimeError("\'ceph osd dump\' failed - " + e)
-
-  mo = rec.search(o);
-  if not mo or mo.group(2) == '0.000000':
-    print >> sys.stderr, "Unable to get cluster creation date"
-
-  return mo.group(2)
+  oj = json.loads(o)
+  return oj['created']
 
 def bytes_pretty_to_raw(byte_count, byte_scale):
   if byte_scale == 'kB':
@@ -69,49 +55,35 @@ def bytes_pretty_to_raw(byte_count, byte_scale):
   return byte_count
 
 def get_nums():
-  (rc, o, e) = run_command(['ceph', '-s'])
+  (rc, o, e) = run_command(['ceph', '-s', '-f', 'json'])
   if rc is not 0:
     raise RuntimeError("\'ceph -s\' failed - " + e)
 
-  num_mons = 0
-
-  mo = re.search('(.*monmap\ .*:\ )(\d+)(.*)', o)
-  if not mo:
-    raise RuntimeError("Unmatched pattern for monmap in \'ceph status\'")
-  else:
-    num_mons = int(mo.group(2))
-
-  num_osds = 0
-  mo = re.search('.*osdmap.*(\d+).*(\d+).*(\d+).*', o)
-  if not mo:
-    raise RuntimeError("Unmatched pattern for osdmap in \'ceph status\'")
-  else:
-    num_osds = int(mo.group(1))
+  oj = json.loads(o)
+  num_mons = len(oj['monmap']['mons'])
+  num_osds = int(oj['osdmap']['osdmap']['num_in_osds'])
+  num_mdss = oj['mdsmap']['in']
 
-  num_mdss = 0
-  mo = re.search('.*mdsmap\ e\d+.*(\d+)/(\d+)/(\d+).*', o)
-  if mo:
-    num_mdss = int(mo.group(2));
+  pgmap = oj['pgmap']
+  num_pgs = pgmap['num_pgs']
+  num_bytes = pgmap['data_bytes']
 
-  num_pgs = 0
-  num_pools = 0
-  num_bytes = 0
+  (rc, o, e) = run_command(['ceph', 'pg', 'dump', 'pools', '-f', 'json-pretty'])
+  if rc is not 0:
+    raise RuntimeError("\'ceph pg dump pools\' failed - " + e)
+  pools = json.loads(o)
+  num_pools = len(pools)
   num_objs = 0
-  mo = re.search('.*pgmap\ v\d+:\ (\d+).*,\ (\d+).*,\ (\d+)\ (\S+)\ data,\ (\d+).*', o)
-  if not mo:
-    raise RuntimeError("Unmatched pattern for pgmap in \'ceph status\'")
-  else:
-    num_pgs = int(mo.group(1))
-    num_pools = int(mo.group(2))
-    byte_count = int(mo.group(3))
-    byte_scale = mo.group(4)
-    num_objs = int(mo.group(5))
+  for p in pools:
+    num_objs += p['stat_sum']['num_objects']
+
   nums = {'num_mons':num_mons,
           'num_osds':num_osds,
           'num_mdss':num_mdss,
           'num_pgs':num_pgs,
+          'num_bytes':num_bytes,
           'num_pools':num_pools,
-          'num_bytes': bytes_pretty_to_raw(byte_count, byte_scale),
           'num_objects':num_objs}
   return nums
 
@@ -153,18 +125,15 @@ def get_crush_types():
   return crush_map
 
 def get_pool_metadata():
-  (rc, o, e) = run_command(['ceph', 'osd', 'dump'])
+  (rc, o, e) = run_command(['ceph', 'osd', 'dump', '-f', 'json'])
   if rc is not 0:
     raise RuntimeError("\'ceph osd dump\' failed - " + e)
 
-  result = re.findall("pool\ (\d+)\ '(\S+)'\ (\S+)\ size\ (\d+)", o)
-  if len(result) is 0:
-    raise RuntimeError("Unmatched pattern for \'pool\' in \'ceph osd dump\'")
-
   pool_meta = []
-  proc = lambda x: {'id':x[0], 'type':x[2], 'size':int(x[3])}
-  for r in result:
-    pool_meta.append(proc(r))
+  oj = json.loads(o)
+  proc = lambda x: {'id':x['pool'], 'type':x['type'], 'size':x['size']}
+  for p in oj['pools']:
+    pool_meta.append(proc(p))
 
   return pool_meta
 
index 32f528a43c17f69401ce50e9b79c618313fc01e4..94d98ffc04d2f6e1c18892ef56e48ba3084d9428 100644 (file)
@@ -56,8 +56,8 @@ class pools_info(Base):
 
   index = Column(Integer, primary_key=True)
   vid = Column(ForeignKey('version_info.index'))
-  pool_id = Column(String(8))
-  pool_type = Column(String(16))
+  pool_id = Column(Integer)
+  pool_type = Column(Integer)
   pool_rep_size = Column(Integer)
 
 class os_info(Base):
index 4915f5afd3f886675734e4fe291ac1e6e2c7ad13..194ec637be905a84409415dab9d893e37f4c24e2 100644 (file)
   },
   "pool_metadata": [
     {
-      "type": "replicated",
-      "id": "0",
+      "type": 1,
+      "id": 0,
       "size": 3
     },
     {
-      "type": "replicated",
-      "id": "1",
+      "type": 1,
+      "id": 1,
       "size": 3
     },
     {
-      "type": "replicated",
-      "id": "2",
+      "type": 1,
+      "id": 2,
       "size": 3
     }
   ],