1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/usr/bin/env python
# coding: utf-8
#
# Ceph - scalable distributed file system
#
# Copyright (C) 2017 OVH
#
# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2, as published by the Free Software
# Foundation. See file COPYING.
#
import json
import subprocess
import time
import os
import argparse
def shorten(val):
if isinstance(val, str):
return val
for u in ((3, ''), (6, 'k'), (9, 'M'), (12, 'G'), (15, 'T')):
if val < 10**u[0]:
return "{}{}".format(int(val / (10 ** (u[0]-3))), u[1])
return val
def print_histogram(asok, logger, counter, last):
try:
out = subprocess.check_output(
"ceph --admin-daemon {} perf histogram dump".format(asok),
shell=True)
j = json.loads(out.decode('utf-8'))
except Exception as e:
return (last,
"Couldn't connect to admin socket, result: \n{}".format(e))
current = j['osd'][counter]['values']
axes = j['osd'][counter]['axes']
content = ""
content += "{}:\n".format(axes[1]['name'])
for r in axes[1]['ranges']:
content += "{0: >4} ".format(
shorten(r['min']) if 'min' in r else '')
content += "\n"
for r in axes[1]['ranges']:
content += "{0: >4} ".format(
shorten(r['max']) if 'max' in r else '')
content += "\n"
content += ("{0: >"+str(len(axes[1]['ranges'])*5+14)+"}:\n").format(
axes[0]['name'])
for i in range(len(current)):
for j in range(len(current[i])):
try:
diff = current[i][j] - last[i][j]
except IndexError:
diff = '-'
content += "{0: >4} ".format(shorten(diff))
r = axes[0]['ranges'][i]
content += "{0: >6} : {1}\n".format(
shorten(r['min']) if 'min' in r else '',
shorten(r['max']) if 'max' in r else '')
return (current, content)
def loop_print(asok, logger, counter):
last = []
while True:
last, content = print_histogram(asok, logger, counter, last)
print("{}{}".format("\n"*100, content))
time.sleep(1)
def main():
parser = argparse.ArgumentParser(
description='Continuously display ceph performance histogram')
parser.add_argument(
'--asok',
type=str,
default='/var/run/ceph/*.asok',
help='Path to asok file, can use wildcards')
parser.add_argument(
'--logger',
type=str,
default='osd')
parser.add_argument(
'--counter',
type=str,
default='op_w_latency_in_bytes_histogram')
args = parser.parse_args()
loop_print(args.asok, args.logger, args.counter)
if __name__ == '__main__':
main()
|