Completed
Push — master ( da3b73...3279ec )
by Kenny
01:17
created

Plugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 33
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onstart() 0 3 1
A onreload() 0 3 1
A onstop() 0 3 1
A __init__() 0 10 1
1
# -*- coding: utf-8 -*-
2
"""Abstract classes that define the reader and writer plugin base classes.
3
4
.. moduleauthor:: Kenny Freeman <[email protected]>
5
6
"""
7
__author__ = 'Kenny Freeman'
8
__email__ = '[email protected]'
9
__license__ = "ISCL"
10
__docformat__ = 'reStructuredText'
11
12
from abc import ABCMeta, abstractmethod
13
14
15
class Plugin(object):
16
    """The base class for all plugins.
17
18
    :param config: an instance of plumd.conf configuration helper
19
    :type config: conf
20
    """
21
    defaults = {}
22
23
    def __init__(self, log, config):
24
        """reader abstract class constructor - each plugin must sub class.
25
26
        :param config: an instance of plumd.conf configuration helper
27
        :type config: conf
28
        """
29
        self.config = config
30
        self.log = log
31
        # plugins can set their own defaults byt defining self.defaults
32
        self.config.defaults(self.defaults)
33
34
35
    def onstart(self):
36
        """onstart() is called before the first call to push()."""
37
        pass
38
39
40
    def onstop(self):
41
        """onstop() is called just before the main process exits."""
42
        pass
43
44
45
    def onreload(self):
46
        """onreload() is called to reload configuration at runtime."""
47
        raise NotImplementedError("todo")
48
49
50
class Reader(Plugin):
51
    """An abstract base class that all writer pluguns subclass."""
52
    __metaclass__ = ABCMeta
53
54
    @abstractmethod
55
    def poll(self):
56
        """Reader plugins must define this method, it measures and returns a
57
        metrics string.
58
59
        format <name:str> <value:float|int> <timestamp:time.time()>\n[...]
60
        set to change to a python object.
61
62
        :rtype: str
63
        """
64
        # this will never get called
65
        raise NotImplementedError("poll() not defined")
66
67
68
class Writer(Plugin):
69
    """An abstract base class that all writer pluguns subclass."""
70
    __metaclass__ = ABCMeta
71
72
    @abstractmethod
73
    def push(self, metrics):
74
        """Writer plugins must define this method, it accepts a metrics string
75
        and sends to its backend(s).
76
77
        :param metrics: metrics collection from reader poll() call.
78
79
        :type metrics: str
80
        """
81
        # this will never get called
82
        raise NotImplementedError("push() not defined")
83