From 09a317fbd770bb33d8d642b8ede732862191cdae Mon Sep 17 00:00:00 2001 From: Babu Shanmugam Date: Fri, 7 Mar 2014 06:47:06 +0000 Subject: [PATCH] Made crush_types to be a map of type to count, so we can tell how many racks/rows/hosts/etc are there Signed-off-by: Babu Shanmugam --- README.md | 27 ++++++++++++++++----------- client/ceph-brag | 29 ++++++++++++++++++++++++++--- server/ceph_brag/json.py | 8 ++++++-- server/ceph_brag/model/db.py | 21 ++++++++++++++++++--- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7526480f1f81d..cb2622100871d 100644 --- a/README.md +++ b/README.md @@ -33,17 +33,22 @@ Run 'ceph-brag -h' to get the usage information of this tool. "num_mons": 1 }, "crush_types": [ - "osd", - "host", - "chassis", - "rack", - "row", - "pdu", - "pod", - "room", - "datacenter", - "region", - "root" + { + "type": "osd" + "count": 2, + }, + { + "type": "rack" + "count": 1, + }, + { + "type": "host" + "count": 1, + }, + { + "type": "root" + "count": 1, + } ], "ownership": { "organization": "eNovance", diff --git a/client/ceph-brag b/client/ceph-brag index e97b0c45cafd1..b28bcd4926731 100755 --- a/client/ceph-brag +++ b/client/ceph-brag @@ -7,6 +7,7 @@ import json import sys import ast import requests +from collections import Counter CLUSTER_UUID_NAME='cluster-uuid' CLUSTER_OWNERSHIP_NAME='cluster-ownership' @@ -107,11 +108,33 @@ def get_crush_types(): if crush_dump['types'] is None: raise RuntimeError("\'types\' item missing in \'ceph osd crush dump\'") - crush_types = [] + crush_types = {} for t in crush_dump['types']: - crush_types.append(t['name']) + crush_types[t['type_id']] = t['name'] + + buckets = {} + items_list = [] + for bucket in crush_dump['buckets']: + buckets[bucket['id']] = bucket['type_id'] + for item in bucket['items']: + items_list.append(item['id']) + + crush_map = [] + counter = Counter(items_list) + append = lambda t,c: crush_map.append({'type':t, 'count':c}) + for id,count in counter.items(): + if id in buckets: + append(crush_types[buckets[id]], + count) + del buckets[id] + else: + append(crush_types[id], count) + + #the root item + for id,type_id in buckets.items(): + append(crush_types[type_id], 1) - return crush_types + return crush_map def get_pool_metadata(): (rc, o, e) = run_command(['ceph', 'osd', 'dump']) diff --git a/server/ceph_brag/json.py b/server/ceph_brag/json.py index a97e580466861..f272209477ed9 100644 --- a/server/ceph_brag/json.py +++ b/server/ceph_brag/json.py @@ -31,6 +31,11 @@ def jsonify_components_info(comps): num_mons=comps.num_mons ) +@jsonify.register(db.crush_types) +def jsonify_crush_types(crush): + return dict(type=crush.crush_type, + count=crush.crush_count) + @jsonify.register(db.pools_info) def jsonify_pools_info(pool): return dict(size=pool.pool_rep_size, @@ -56,11 +61,10 @@ def jsonify_brag(b): 'email':b.ci.contact_email, 'name':b.ci.cluster_name } - crush_types=b.comps.crush_types.split(',') return dict(uuid=b.ci.uuid, cluster_creation_date=str(b.ci.cluster_creation_date), components_count=b.comps, - crush_types=crush_types, + crush_types=b.crush, ownership=ownership, pool_metadata=b.pools, sysinfo=b.osds diff --git a/server/ceph_brag/model/db.py b/server/ceph_brag/model/db.py index 0a22d15074750..4696a31332732 100644 --- a/server/ceph_brag/model/db.py +++ b/server/ceph_brag/model/db.py @@ -43,7 +43,14 @@ class components_info(Base): num_pools = Column(Integer) num_mdss = Column(Integer) num_mons = Column(Integer) - crush_types = Column(String(256)) + +class crush_types(Base): + __tablename__ = 'crush_types' + + index = Column(Integer, primary_key=True) + vid = Column(ForeignKey('version_info.index')) + crush_type = Column(String(16)) + crush_count = Column(Integer) class pools_info(Base): __tablename__ = 'pools_info' @@ -80,6 +87,7 @@ class brag(object): if self.ci is not None and self.vi is not None: self.comps = Session.query(components_info).filter_by(vid=self.vi.index).first() + self.crush = Session.query(crush_types).filter_by(vid=self.vi.index).all() self.pools = Session.query(pools_info).filter_by(vid=self.vi.index).all() self.osds = Session.query(osds_info).filter_by(vid=self.vi.index).all() @@ -160,10 +168,15 @@ def put_new_version(data): num_pgs=comps_count['num_pgs'], num_pools=comps_count['num_pools'], num_mdss=comps_count['num_mdss'], - num_mons=comps_count['num_mons'], - crush_types=','.join(info['crush_types'])) + num_mons=comps_count['num_mons']) Session.add(comps_info) + def add_crush_types(vi): + for c in info['crush_types']: + Session.add(crush_types(vid=vi.index, + crush_type=c['type'], + crush_count=c['count'])) + def add_pools_info(vi): pools = info['pool_metadata'] for p in pools: @@ -195,6 +208,7 @@ def put_new_version(data): vi = Session.query(version_info).filter_by(cluster_id=ci.index, version_number=ci.num_versions).first() add_components_info(vi) + add_crush_types(vi) add_pools_info(vi) add_osds_info(vi) @@ -205,6 +219,7 @@ def delete_uuid(uuid): for v in Session.query(version_info).filter_by(cluster_id=ci.index).all(): Session.query(components_info).filter_by(vid=v.index).delete() + Session.query(crush_types).filter_by(vid=v.index).delete() Session.query(pools_info).filter_by(vid=v.index).delete() Session.query(osds_info).filter_by(vid=v.index).delete() Session.flush() -- 2.39.5