summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBabu Shanmugam <anbu@enovance.com>2014-03-10 06:11:03 +0000
committerBabu Shanmugam <anbu@enovance.com>2014-03-10 06:11:03 +0000
commit18506ad6e5a0724e040593c20ff1463f211bceec (patch)
tree575d0b0213ed0c0fa7f72943bd7d52a1206598e7
parent4cb6b2a1bf1467e6b21a13e1bd9a78dd2defcea7 (diff)
downloadceph-18506ad6e5a0724e040593c20ff1463f211bceec.tar.gz
Removed all regular expression parsing and used '-f json' instead
Signed-off-by: Babu Shanmugam <anbu@enovance.com>
-rw-r--r--README.md12
-rwxr-xr-xclient/ceph-brag83
-rw-r--r--server/ceph_brag/model/db.py4
-rw-r--r--server/sample.json12
4 files changed, 40 insertions, 71 deletions
diff --git a/README.md b/README.md
index 6eabcf79c0b..55af44f83a6 100644
--- 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": {
diff --git a/client/ceph-brag b/client/ceph-brag
index 8bc2b4304e0..e07ad01b663 100755
--- a/client/ceph-brag
+++ b/client/ceph-brag
@@ -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
diff --git a/server/ceph_brag/model/db.py b/server/ceph_brag/model/db.py
index 32f528a43c1..94d98ffc04d 100644
--- a/server/ceph_brag/model/db.py
+++ b/server/ceph_brag/model/db.py
@@ -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):
diff --git a/server/sample.json b/server/sample.json
index 4915f5afd3f..194ec637be9 100644
--- a/server/sample.json
+++ b/server/sample.json
@@ -36,18 +36,18 @@
},
"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
}
],