From 90067778aac5c6995871af0f5d4764c0846087d7 Mon Sep 17 00:00:00 2001 From: Babu Shanmugam Date: Thu, 30 Jan 2014 05:22:59 +0000 Subject: [PATCH] 1. Updated README.md with sample output 2. Remove 'osd_hosts' entry from json and added that information as part of sys_info 3. In the 'num_components' entry, 'bytes' entry is replaced to contain an object with 'count' and 'scale' members --- README.md | 77 ++++++++++++++++++++++++++++++++ ceph-brag | 130 ++++++++++++++++++++++++++---------------------------- 2 files changed, 139 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 43772394acd0c..9d9dc34cc5050 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,80 @@ ceph-brag uses 'ceph' python script. Hence, before executing ceph-brag script en Runtime instructions: --------------------- Run 'ceph-brag -h' to get the usage information of this tool. + +Sample output: +-------------- + + { + "cluster_creation_date": "2014-01-16 13:38:41.928551", + "uuid": "20679d0e-04b1-4004-8ee9-45ac271510e9", + "components_count": { + "bytes": "0 bytes", + "osds": 1, + "objects": 0, + "pgs": 192, + "pools": 3, + "mdss": 1, + "mons": 1 + }, + "crush_types": [ + "osd", + "host", + "chassis", + "rack", + "row", + "pdu", + "pod", + "room", + "datacenter", + "region", + "root" + ], + "hosts": [ + { + "ip": "127.0.0.1", + "hostname": "ceph-brag" + } + ], + "ownership": { + "organization": "eNovance", + "email": "mail@enovance.com", + "description": "Use case", + "name": "Cluster1" + }, + "pool_metadata": [ + { + "rep_size": 3, + "id": "0", + "name": "data" + }, + { + "rep_size": 3, + "id": "1", + "name": "metadata" + }, + { + "rep_size": 3, + "id": "2", + "name": "rbd" + } + ], + "sysinfo": [ + { + "hw_info": { + "swap_kb": 0, + "arch": "x86_64", + "cpu": "Intel Xeon E312xx (Sandy Bridge)", + "mem_kb": 2051648 + }, + "id": 0, + "os_info": { + "version": "3.2.0-23-virtual", + "os": "Linux", + "description": "#36-Ubuntu SMP Tue Apr 10 22:29:03 UTC 2012", + "distro": "Ubuntu 12.04 precise (Ubuntu 12.04 LTS)" + }, + "ceph_version": "ceph version 0.75-229-g4050eae (4050eae32cd77a1c210ca11d0f12c74daecb1bd3)" + } + ] + } diff --git a/ceph-brag b/ceph-brag index 7a1548d15e42a..f37b61864f3f7 100755 --- a/ceph-brag +++ b/ceph-brag @@ -79,20 +79,21 @@ def get_nums(): num_pools = 0 num_bytes = 0 num_objs = 0 - mo = re.search('.*pgmap\ v\d+:\ (\d+).*,\ (\d+).*,\ (\d+.*)\ data,\ (\d+).*', o) + 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)) - num_bytes = mo.group(3) - num_objs = int(mo.group(4)) + byte_count = int(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':num_bytes, + 'bytes': {'count':byte_count, 'scale':byte_scale}, 'objects':num_objs} return nums @@ -130,84 +131,76 @@ def get_pool_metadata(): return pool_meta -def get_sysinfo(): +def get_sysinfo(max_osds): sysinfo = [] count = 0 + osd_metadata_available = False - while True: - (rc, o, e) = run_command(['ceph', 'osd', 'metadata', str(count)]) - if rc is not 0: - break - + while count < max_osds: meta = {'id':count} - os_info = {} - hw_info = {} - - jmeta = json.loads(o) - count = count + 1 - - meta['ceph_version'] = jmeta['ceph_version'] - - os_info['os'] = jmeta['os'] - os_info['version'] = jmeta['kernel_version'] - os_info['description'] = jmeta['kernel_description'] - - try: - distro = jmeta['distro'] + ' ' - distro += jmeta['distro_version'] + ' ' - distro += jmeta['distro_codename'] + ' (' - distro += jmeta['distro_description'] + ')' - os_info['distro'] = distro - except KeyError as ke: - pass - meta['os_info'] = os_info - - hw_info['cpu'] = jmeta['cpu'] - hw_info['arch'] = jmeta['arch'] - hw_info['mem_kb'] = int(jmeta['mem_total_kb']) - hw_info['swap_kb'] = int(jmeta['mem_swap_kb']) - meta['hw_info'] = hw_info + (rc, o, e) = run_command(['ceph', 'osd', 'metadata', str(count)]) + if rc is 0: + if osd_metadata_available is False: + osd_metadata_available = True + os_info = {} + hw_info = {} + nw_info = {} + + jmeta = json.loads(o) + + meta['ceph_version'] = jmeta['ceph_version'] + + os_info['os'] = jmeta['os'] + os_info['version'] = jmeta['kernel_version'] + os_info['description'] = jmeta['kernel_description'] + + try: + distro = jmeta['distro'] + ' ' + distro += jmeta['distro_version'] + ' ' + distro += jmeta['distro_codename'] + ' (' + distro += jmeta['distro_description'] + ')' + os_info['distro'] = distro + except KeyError as ke: + pass + meta['os_info'] = os_info + + hw_info['cpu'] = jmeta['cpu'] + hw_info['arch'] = jmeta['arch'] + hw_info['mem_kb'] = int(jmeta['mem_total_kb']) + hw_info['swap_kb'] = int(jmeta['mem_swap_kb']) + meta['hw_info'] = hw_info + + (ip, hname) = get_osd_host(count) + nw_info['address'] = ip + nw_info['hostname'] = hname + meta['nw_info'] = nw_info sysinfo.append(meta) + count = count + 1 - if len(sysinfo) is 0: + if osd_metadata_available is False: print >> sys.stderr, "'ceph osd metadata' is not available at all" return sysinfo -def get_osd_hosts(): - locs = [] - osd_id = 0 +def get_osd_host(osd_id): loc = {} - while True: - (rc, o, e) = run_command(['ceph', 'osd', 'find', str(osd_id)]) - if rc is not 0: - break - - jloc = json.loads(o) - - mo = re.search("(\d+.\d+.\d+.\d+).*", jloc['ip']) - if mo is None: - #Might be in ipv6 format, TODO: Verify - return None; - - ip = mo.group(1) - host = jloc['crush_location']['host'] + (rc, o, e) = run_command(['ceph', 'osd', 'find', str(osd_id)]) + if rc is not 0: + raise RuntimeError("\'ceph osd find\' failed - " + e) - if ip not in loc: - loc[ip] = host - elif loc[ip] != host: - #Mismatching details - print >> sys.stderr, "ip-hostname conflict" - assert(0) + jloc = json.loads(o) - for k,v in loc.iteritems(): - locs.append({'ip':k, 'hostname':v}) + mo = re.search("(\d+.\d+.\d+.\d+).*", jloc['ip']) + if mo is None: + #Might be in ipv6 format, TODO: Verify + return None; - osd_id += 1 + ip = mo.group(1) + host = jloc['crush_location']['host'] - return locs + return (ip, host) def get_ownership_info(): (rc, o, e) = run_command(['ceph', 'config-key', 'get', @@ -221,11 +214,12 @@ def output_json(): out = {} out['uuid'] = get_uuid() out['cluster_creation_date'] = get_cluster_creation_date() - out['components_count'] = get_nums() - out['hosts'] = get_osd_hosts() + nums = get_nums() + num_osds = int(nums['osds']) + out['components_count'] = nums out['crush_types'] = get_crush_types() out['pool_metadata'] = get_pool_metadata() - out['sysinfo'] = get_sysinfo() + out['sysinfo'] = get_sysinfo(num_osds) owner = get_ownership_info() if owner is not None: -- 2.39.5