From: Babu Shanmugam Date: Thu, 6 Mar 2014 07:58:25 +0000 (+0000) Subject: 1. simplified the 'bytes' info to just be bytes X-Git-Tag: v0.78~41^2^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=da97feeaad8d730995f2a44875c2bdcf48f7e9e7;p=ceph.git 1. simplified the 'bytes' info to just be bytes 2. prefix all the members of the components_info with 'num_' Signed-off-by: Babu Shanmugam --- diff --git a/README.md b/README.md index 1cbc11b4a7d2..f04f5b465d5f 100644 --- a/README.md +++ b/README.md @@ -24,16 +24,13 @@ 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": { - "bytes": { - "count": 0, - "scale": "bytes" - }, - "osds": 1, - "objects": 0, - "pgs": 192, - "pools": 3, - "mdss": 1, - "mons": 1 + "num_bytes": '0 bytes', + "num_osds": 1, + "num_objects": 0, + "num_pgs": 192, + "num_pools": 3, + "num_mdss": 1, + "num_mons": 1 }, "crush_types": [ "osd", diff --git a/client/ceph-brag b/client/ceph-brag index 838189942c58..f9e778f603a7 100755 --- a/client/ceph-brag +++ b/client/ceph-brag @@ -86,16 +86,16 @@ def get_nums(): else: num_pgs = int(mo.group(1)) num_pools = int(mo.group(2)) - byte_count = int(mo.group(3)) + byte_count = mo.group(3) byte_scale = mo.group(4) num_objs = int(mo.group(5)) - nums = {'mons':num_mons, - 'osds':num_osds, - 'mdss':num_mdss, - 'pgs':num_pgs, - 'pools':num_pools, - 'bytes': {'count':byte_count, 'scale':byte_scale}, - 'objects':num_objs} + nums = {'num_mons':num_mons, + 'num_osds':num_osds, + 'num_mdss':num_mdss, + 'num_pgs':num_pgs, + 'num_pools':num_pools, + 'num_bytes': byte_count + " " + byte_scale, + 'num_objects':num_objs} return nums def get_crush_types(): @@ -221,7 +221,7 @@ def output_json(): out['uuid'] = get_uuid() out['cluster_creation_date'] = get_cluster_creation_date() nums = get_nums() - num_osds = int(nums['osds']) + num_osds = int(nums['num_osds']) out['components_count'] = nums out['crush_types'] = get_crush_types() out['pool_metadata'] = get_pool_metadata() diff --git a/server/ceph_brag/json.py b/server/ceph_brag/json.py index 856ea4eaf894..325a0f4e6126 100644 --- a/server/ceph_brag/json.py +++ b/server/ceph_brag/json.py @@ -22,13 +22,13 @@ def jsonify_cluster_info(ci): @jsonify.register(db.components_info) def jsonify_components_info(comps): return dict( - bytes={'count':comps.byte_count, 'scale':comps.byte_scale}, - osds=comps.num_osds, - objects=comps.num_objects, - pgs=comps.num_pgs, - pools=comps.num_pools, - mdss=comps.num_mdss, - mons=comps.num_mons + num_bytes=db.bytes_raw_to_pretty(comps.num_bytes), + num_osds=comps.num_osds, + num_objects=comps.num_objects, + num_pgs=comps.num_pgs, + num_pools=comps.num_pools, + num_mdss=comps.num_mdss, + num_mons=comps.num_mons ) @jsonify.register(db.pools_info) diff --git a/server/ceph_brag/model/db.py b/server/ceph_brag/model/db.py index 974b37ce2550..6a2a828d40ec 100644 --- a/server/ceph_brag/model/db.py +++ b/server/ceph_brag/model/db.py @@ -1,7 +1,9 @@ import json from datetime import datetime +import re from sqlalchemy.orm import sessionmaker, scoped_session -from sqlalchemy import Column, Integer, String, DateTime, ForeignKey +from sqlalchemy import Column, Integer, String, \ + DateTime, ForeignKey, BigInteger from sqlalchemy import PrimaryKeyConstraint from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr @@ -34,8 +36,7 @@ class components_info(Base): index = Column(Integer, primary_key=True) vid = Column(ForeignKey('version_info.index')) - byte_count = Column(Integer) - byte_scale = Column(String(8)) + num_bytes = Column(BigInteger) num_osds = Column(Integer) num_objects = Column(Integer) num_pgs = Column(Integer) @@ -82,6 +83,46 @@ class brag(object): 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() +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(): @@ -111,15 +152,15 @@ 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, - byte_count=comps_count['bytes']['count'], - byte_scale=comps_count['bytes']['scale'], - num_osds=comps_count['osds'], - num_objects=comps_count['objects'], - num_pgs=comps_count['pgs'], - num_pools=comps_count['pools'], - num_mdss=comps_count['mdss'], - num_mons=comps_count['mons'], + num_bytes=bytes_pretty_to_raw(nbytes), + num_osds=comps_count['num_osds'], + num_objects=comps_count['num_objects'], + 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'])) Session.add(comps_info)