blob: 3a2d926225e17c87e7f83256d036badfb4159446 [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
19net_values_pos = [
20 (0, 'recv_bytes', True),
21 (1, 'recv_packets', True),
22 (8, 'send_bytes', True),
23 (9, 'send_packets', True),
24]
25
26
27@provides("net-io")
28def net_stat(disallowed_prefixes=('docker',), allowed_prefixes=None):
29 results = {}
30
31 for line in open('/proc/net/dev').readlines()[2:]:
32 dev_name, stats = line.split(":", 1)
33 dev_name = dev_name.strip()
34 vals = stats.split()
35
36 dev_ok = is_dev_accepted(dev_name,
37 disallowed_prefixes,
38 allowed_prefixes)
39 if dev_ok:
40 for pos, name, accum_val in net_values_pos:
41 sensor_name = "{0}.{1}".format(dev_name, name)
42 results[sensor_name] = SensorInfo(int(vals[pos]), accum_val)
43 return results