4 # Ceph - scalable distributed file system
6 # Copyright (C) 2017 OVH
8 # This is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public
10 # License version 2, as published by the Free Software
11 # Foundation. See file COPYING.
22 if isinstance(val, str):
24 for u in ((3, ''), (6, 'k'), (9, 'M'), (12, 'G'), (15, 'T')):
26 return "{}{}".format(int(val / (10 ** (u[0]-3))), u[1])
30 def print_histogram(asok, logger, counter, last):
33 out = subprocess.check_output(
34 "ceph --admin-daemon {} perf histogram dump".format(asok),
36 j = json.loads(out.decode('utf-8'))
37 except Exception as e:
39 "Couldn't connect to admin socket, result: \n{}".format(e))
41 current = j['osd'][counter]['values']
42 axes = j['osd'][counter]['axes']
45 content += "{}:\n".format(axes[1]['name'])
46 for r in axes[1]['ranges']:
47 content += "{0: >4} ".format(
48 shorten(r['min']) if 'min' in r else '')
50 for r in axes[1]['ranges']:
51 content += "{0: >4} ".format(
52 shorten(r['max']) if 'max' in r else '')
55 content += ("{0: >"+str(len(axes[1]['ranges'])*5+14)+"}:\n").format(
58 for i in range(len(current)):
59 for j in range(len(current[i])):
61 diff = current[i][j] - last[i][j]
64 content += "{0: >4} ".format(shorten(diff))
66 r = axes[0]['ranges'][i]
67 content += "{0: >6} : {1}\n".format(
68 shorten(r['min']) if 'min' in r else '',
69 shorten(r['max']) if 'max' in r else '')
70 return (current, content)
73 def loop_print(asok, logger, counter):
77 last, content = print_histogram(asok, logger, counter, last)
78 print("{}{}".format("\n"*100, content))
83 parser = argparse.ArgumentParser(
84 description='Continuously display ceph performance histogram')
88 default='/var/run/ceph/*.asok',
89 help='Path to asok file, can use wildcards')
97 default='op_w_latency_in_bytes_histogram')
98 args = parser.parse_args()
100 loop_print(args.asok, args.logger, args.counter)
103 if __name__ == '__main__':