blob: 4e49495ce509b9a8ae7ab1d275bbc651b9c0d05f [file] [log] [blame]
Ved-vampir602a5172015-03-16 15:22:36 +03001from discover import provides
2from utils import SensorInfo, is_dev_accepted
3
4# 0 - cpu name
5# 1 - user: normal processes executing in user mode
6# 2 - nice: niced processes executing in user mode
7# 3 - system: processes executing in kernel mode
8# 4 - idle: twiddling thumbs
9# 5 - iowait: waiting for I/O to complete
10# 6 - irq: servicing interrupts
11# 7 - softirq: servicing softirqs
12
13io_values_pos = [
Ved-vampirbb783a12015-03-18 11:21:48 +030014 (1, 'user_processes', True),
15 (2, 'nice_processes', True),
16 (3, 'system_processes', True),
Ved-vampir602a5172015-03-16 15:22:36 +030017 (4, 'idle_time', True),
18]
19
20
21@provides("system-cpu")
22def syscpu_stat(disallowed_prefixes=('intr', 'ctxt', 'btime', 'processes',
23 'procs_running', 'procs_blocked', 'softirq'),
24 allowed_prefixes=None):
25 results = {}
Ved-vampir602a5172015-03-16 15:22:36 +030026
27 for line in open('/proc/stat'):
28 vals = line.split()
29 dev_name = vals[0]
30
31 dev_ok = is_dev_accepted(dev_name,
32 disallowed_prefixes,
33 allowed_prefixes)
34
35 if dev_ok:
36 for pos, name, accum_val in io_values_pos:
37 sensor_name = "{0}.{1}".format(dev_name, name)
38 results[sensor_name] = SensorInfo(int(vals[pos]), accum_val)
Ved-vampir602a5172015-03-16 15:22:36 +030039 return results
40