1 | # -*- coding: utf-8 -*- |
||
2 | """Reader plugin to record uptime from /proc on Linux.""" |
||
3 | import multiprocessing |
||
4 | |||
5 | import plumd |
||
6 | from plumd.util import get_file |
||
7 | |||
8 | __author__ = 'Kenny Freeman' |
||
9 | __email__ = '[email protected]' |
||
10 | __license__ = "ISCL" |
||
11 | __docformat__ = 'reStructuredText' |
||
12 | |||
13 | |||
14 | class Uptime(plumd.Reader): |
||
15 | """Plugin to measure various kernel metrics from /proc.""" |
||
16 | |||
17 | defaults = { |
||
18 | 'poll.interval': 10, |
||
19 | 'proc_path': '/proc' |
||
20 | } |
||
21 | |||
22 | def __init__(self, log, config): |
||
23 | """Plugin to measure kernel metrics from /proc/uptime. |
||
24 | |||
25 | :param log: A logger |
||
26 | :type log: logging.RootLogger |
||
27 | :param config: a plumd.config.Conf configuration helper instance. |
||
28 | :type config: plumd.config.Conf |
||
29 | """ |
||
30 | super(Uptime, self).__init__(log, config) |
||
31 | self.config.defaults(Uptime.defaults) |
||
32 | self.proc_file = "{0}/uptime".format(config.get('proc_path')) |
||
33 | |||
34 | def poll(self): |
||
35 | """Return uptime from proc file swap. |
||
36 | |||
37 | :rtype: plumd.ResultSet |
||
38 | """ |
||
39 | return plumd.ResultSet(self.check()) |
||
40 | |||
41 | def check(self): |
||
42 | """Return uptime from proc file swap. |
||
43 | |||
44 | :rtype: list |
||
45 | """ |
||
46 | result = plumd.Result("uptime") |
||
47 | # read and process /proc/stat |
||
48 | up, idle = get_file(self.proc_file).strip().split() |
||
49 | pidle = float(idle) / float(up) * 100 / multiprocessing.cpu_count() |
||
0 ignored issues
–
show
|
|||
50 | result.add(plumd.Float("up", up)) |
||
51 | result.add(plumd.Float("idle", idle)) |
||
52 | result.add(plumd.Float("idle_percent", pidle)) |
||
53 | return [result] |
||
54 |
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.