| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # -*- coding: utf-8 -*- |
||
| 13 | class LoadAverage(plumd.plugins.Reader): |
||
| 14 | """Plugin to measure various kernel metrics from /proc.""" |
||
| 15 | defaults = { |
||
| 16 | 'poll.interval': 10, |
||
| 17 | 'proc_path': '/proc' |
||
| 18 | } |
||
| 19 | |||
| 20 | def __init__(self, log, config): |
||
| 21 | """Plugin to measure various kernel metrics from /proc. |
||
| 22 | |||
| 23 | :param log: A logger |
||
| 24 | :type log: logging.RootLogger |
||
| 25 | :param config: a plumd.config.Conf configuration helper instance. |
||
| 26 | :type config: plumd.config.Conf |
||
| 27 | """ |
||
| 28 | super(LoadAverage, self).__init__(log, config) |
||
| 29 | config.defaults(LoadAverage.defaults) |
||
| 30 | self.proc_file = "{0}/loadavg".format(config.get('proc_path')) |
||
| 31 | |||
| 32 | |||
| 33 | def poll(self): |
||
| 34 | """Poll for kernel metrics under /proc. |
||
| 35 | |||
| 36 | :rtype: ResultSet |
||
| 37 | """ |
||
| 38 | return plumd.ResultSet(self.check()) |
||
| 39 | |||
| 40 | |||
| 41 | def check(self): |
||
| 42 | """Return 1, 5 and 15 minute load averages from proc file loadavg. |
||
| 43 | |||
| 44 | :rtype: plumd.Result |
||
| 45 | """ |
||
| 46 | result = plumd.Result("loadavg") |
||
| 47 | dat = [] |
||
| 48 | # read and process /proc/stat |
||
| 49 | dat = get_file(self.proc_file).split() |
||
| 50 | if len(dat) >= 3: |
||
| 51 | result.add(plumd.Float("1", dat[0])) |
||
| 52 | result.add(plumd.Float("5", dat[1])) |
||
| 53 | result.add(plumd.Float("15", dat[2])) |
||
| 54 | return [result] |
||
| 55 |