koder aka kdanilov | dda86d3 | 2015-03-16 11:20:04 +0200 | [diff] [blame] | 1 | from discover import provides |
| 2 | from 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 | |
| 19 | io_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") |
| 32 | def 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 |