blob: 615d3811a3a961d0530a3cb56627e62a0aae60ee [file] [log] [blame]
koder aka kdanilovdda86d32015-03-16 11:20:04 +02001from discover import provides
2from utils import SensorInfo, is_dev_accepted
3
4# 1 - major number
5# 2 - minor mumber
6# 3 - device name
7# 4 - reads completed successfully
8# 5 - reads merged
9# 6 - sectors read
10# 7 - time spent reading (ms)
11# 8 - writes completed
12# 9 - writes merged
13# 10 - sectors written
14# 11 - time spent writing (ms)
15# 12 - I/Os currently in progress
16# 13 - time spent doing I/Os (ms)
17# 14 - weighted time spent doing I/Os (ms)
18
19io_values_pos = [
20 (3, 'reads_completed', True),
21 (5, 'sectors_read', True),
22 (6, 'rtime', True),
23 (7, 'writes_completed', True),
24 (9, 'sectors_written', True),
25 (10, 'wtime', True),
26 (11, 'io_queue', False),
27 (13, 'io_time', True)
28]
29
30
31@provides("block-io")
32def io_stat(disallowed_prefixes=('ram', 'loop'), allowed_prefixes=None):
33 results = {}
34 for line in open('/proc/diskstats'):
35 vals = line.split()
36 dev_name = vals[2]
37
38 dev_ok = is_dev_accepted(dev_name,
39 disallowed_prefixes,
40 allowed_prefixes)
41
42 if dev_ok:
43 for pos, name, accum_val in io_values_pos:
44 sensor_name = "{0}.{1}".format(dev_name, name)
45 results[sensor_name] = SensorInfo(int(vals[pos]), accum_val)
46 return results
Dmitry Yatsushkevich1b31f762015-03-16 13:53:58 -070047
48
49def get_latency(stat1, stat2):
koder aka kdanilovbf83ad92015-03-18 00:11:00 +020050 disks = set(i.split('.', 1)[0] for i in stat1)
Dmitry Yatsushkevich1b31f762015-03-16 13:53:58 -070051 results = {}
koder aka kdanilovbf83ad92015-03-18 00:11:00 +020052
Dmitry Yatsushkevich1b31f762015-03-16 13:53:58 -070053 for disk in disks:
koder aka kdanilovbf83ad92015-03-18 00:11:00 +020054 rdc = disk + '.reads_completed'
55 wrc = disk + '.writes_completed'
56 rdt = disk + '.rtime'
57 wrt = disk + '.wtime'
58 lat = 0.0
59
60 io_ops1 = stat1[rdc].value + stat1[wrc].value
61 io_ops2 = stat2[rdc].value + stat2[wrc].value
62
63 diops = io_ops2 - io_ops1
64
65 if diops != 0:
66 io1 = stat1[rdt].value + stat1[wrt].value
67 io2 = stat2[rdt].value + stat2[wrt].value
68 lat = abs(float(io1 - io2)) / diops
69
70 results[disk + '.latence'] = SensorInfo(lat, False)
Dmitry Yatsushkevich1b31f762015-03-16 13:53:58 -070071
72 return results