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
|
from mgr_module import MgrModule
class Module(MgrModule):
COMMANDS = [
{
"cmd": "iostat",
"desc": "Get IO rates",
"perm": "r",
"poll": "true"
},
]
def __init__(self, *args, **kwargs):
super(Module, self).__init__(*args, **kwargs)
def self_test(self):
r = self.get('io_rate')
assert('pg_stats_delta' in r)
assert('stamp_delta' in r['pg_stats_delta'])
assert('stat_sum' in r['pg_stats_delta'])
assert('num_read_kb' in r['pg_stats_delta']['stat_sum'])
assert('num_write_kb' in r['pg_stats_delta']['stat_sum'])
assert('num_write' in r['pg_stats_delta']['stat_sum'])
assert('num_read' in r['pg_stats_delta']['stat_sum'])
def handle_command(self, inbuf, command):
rd = 0
wr = 0
total = 0
rd_ops = 0
wr_ops = 0
total_ops = 0
ret = ''
if command['prefix'] == 'iostat':
r = self.get('io_rate')
stamp_delta = float(r['pg_stats_delta']['stamp_delta'])
if (stamp_delta > 0):
rd = int(r['pg_stats_delta']['stat_sum']['num_read_kb']) / stamp_delta
wr = int(r['pg_stats_delta']['stat_sum']['num_write_kb']) / stamp_delta
# The values are in kB, but to_pretty_iec() requires them to be in bytes
rd = int(rd) << 10
wr = int(wr) << 10
total = rd + wr
rd_ops = int(r['pg_stats_delta']['stat_sum']['num_read']) / stamp_delta
wr_ops = int(r['pg_stats_delta']['stat_sum']['num_write']) / stamp_delta
total_ops = rd_ops + wr_ops
if 'width' in command:
width = command['width']
else:
width = 80
if command.get('print_header', False):
elems = ['Read', 'Write', 'Total', 'Read IOPS', 'Write IOPS', 'Total IOPS']
ret += self.get_pretty_header(elems, width)
elems = [
self.to_pretty_iec(rd) + 'B/s',
self.to_pretty_iec(wr) + 'B/s',
self.to_pretty_iec(total) + 'B/s',
int(rd_ops),
int(wr_ops),
int(total_ops)
]
ret += self.get_pretty_row(elems, width)
return 0, '', ret
|