blob: 219a48ff5b318431062654e48c5bcc520e103862 [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):
50 disks = set([ i.split('.')[0] for i in stat1 ])
51 results = {}
52 for disk in disks:
53 rdc = disk+'.reads_completed'
54 wrc = disk+'.writes_completed'
55 rdt = disk+'.rtime'
56 wrt = disk+'.wtime'
57 if all(i in stat1 for i in [rdc, wrc, rdt, wrt]) and \
58 all(i in stat2 for i in [rdc, wrc, rdt, wrt]):
59 lat = 0.0
60 if abs((stat1[rdc].value + stat1[wrc].value) - \
61 (stat2[rdc].value + stat2[wrc].value)) > 0:
62 lat = abs(float((stat1[rdt].value + stat1[wrt].value) - \
63 (stat2[rdt].value + stat2[wrt].value)) / \
64 (stat1[rdc].value + stat1[wrc].value) - \
65 (stat2[rdc].value + stat2[wrc].value))
66 results[disk+'.latence'] = SensorInfo(lat, False)
67
68 return results