Completed
Branch master (2f3d56)
by Kenny
01:12
created

Proc   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 2
Metric Value
c 6
b 2
f 2
dl 0
loc 41
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A poll() 0 13 2
A __init__() 0 19 3
1
# -*- coding: utf-8 -*-
2
3
__author__ = 'Kenny Freeman'
4
__email__ = '[email protected]'
5
__license__ = "ISCL"
6
__docformat__ = 'reStructuredText'
7
8
from collections import deque
9
10
import plumd
11
import plumd.plugins
12
13
from plumd.plugins.readers.linux.proc.conntrack import Conntrack
14
from plumd.plugins.readers.linux.proc.diskstats import DiskStats
15
from plumd.plugins.readers.linux.proc.loadavg import LoadAverage
16
from plumd.plugins.readers.linux.proc.mem import Mem
17
from plumd.plugins.readers.linux.proc.netdev import NetDev
18
from plumd.plugins.readers.linux.proc.netsnmp import NetSnmp
19
from plumd.plugins.readers.linux.proc.netstat import Netstat
20
from plumd.plugins.readers.linux.proc.sockstat import SockStat
21
from plumd.plugins.readers.linux.proc.stat import Stat
22
from plumd.plugins.readers.linux.proc.swap import Swap
23
from plumd.plugins.readers.linux.proc.uptime import Uptime
24
25
26
classes = [Conntrack, DiskStats, LoadAverage, Mem, NetDev, NetSnmp, Netstat,
27
           SockStat, Stat, Swap, Uptime]
28
29
30
class Proc(plumd.plugins.Reader):
31
    """Plugin to measure various kernel metrics from /proc."""
32
    defaults = {
33
        'poll.interval': 10,
34
        'disabled_readers': []
35
    }
36
37
    def __init__(self, log, config):
38
        """Plugin to measure various kernel metrics from /proc.
39
40
        :param log: A logger
41
        :type log: logging.RootLogger
42
        :param config: a plumd.config.Conf configuration helper instance.
43
        :type config: plumd.config.Conf
44
        """
45
        super(Proc, self).__init__(log, config)
46
        config.defaults(Proc.defaults)
47
        self.readers = deque()
48
        disabled = config.get('disabled_readers')
49
        for cls in classes:
50
            if cls.__name__ in disabled:
51
                msg = "Proc: skipping disabled reader: {0}"
52
                self.log.warn(msg.format(cls.__name__))
53
                continue
54
            self.log.debug("Proc: initializing reader: {0}".format(cls.__name__))
55
            self.readers.append(cls(log, config))
56
57
58
    def poll(self):
59
        """Poll for kernel metrics under /proc.
60
61
        :rtype: ResultSet
62
        """
63
        ret = plumd.ResultSet([])
64
        for rdr in self.readers:
65
            #self.log.debug("Proc: calling {0}".format(rdr.__class__.__name__))
66
            metrics = rdr.check()
67
            msg = "Proc: {0} returned: {1}"
68
            #self.log.debug(msg.format(rdr.__class__.__name__, metrics))
69
            ret.add_list(metrics)
70
        return ret
71