Back to index

munin  2.0.1
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
munin.Plugin Class Reference

List of all members.

Public Member Functions

def __init__
def __getitem__
def __setitem__
def __delitem__
def __contains__
def run

Public Attributes

 title
 vlabel
 category
 info
 args
 scale

Private Member Functions

def _print_values
def _print_config
def _print_autoconf

Private Attributes

 _values

Detailed Description

Facilitates OO creation of Munin plugins.

#!/usr/bin/env python
from munin import Plugin

p = Plugin("Test measurement", "test/second", category="junk")
p.autoconf = False

for name, value in {'a': 1, 'b': 2}:
    p[ name ].label = name
    p[ name ].value = value

p.run()

(It will itself detect how the script is called and create the proper
output.)

 * If 'autoconf' is a callable, it will be called when running autoconf.

Definition at line 55 of file munin.py.


Constructor & Destructor Documentation

def munin.Plugin.__init__ (   self,
  title,
  vlabel,
  category = "misc",
  info = "",
  args = "",
  scale = True 
)
Sets up the plugin; title, vertical label, category -- all things
that are global for the plugin.

Definition at line 80 of file munin.py.

00080 
00081             scale=True):
00082         """Sets up the plugin; title, vertical label, category -- all things
00083         that are global for the plugin.
00084         """
00085 
00086         self.title = title
00087         self.vlabel = vlabel
00088         self.category = category
00089         self.info = info
00090         self.args = args
00091         self.scale = scale
00092 
00093         self._values = dict()
00094 
00095         assert type(title) is str
00096         assert type(vlabel) is str
00097         assert type(category) is str


Member Function Documentation

def munin.Plugin.__contains__ (   self,
  key 
)

Definition at line 110 of file munin.py.

00110 
00111     def __contains__(self, key):
00112         return key in self._values

def munin.Plugin.__delitem__ (   self,
  key 
)

Definition at line 106 of file munin.py.

00106 
00107     def __delitem__(self, key):
00108         if key in self._values:
00109             del self._values[key]

def munin.Plugin.__getitem__ (   self,
  key 
)

Definition at line 98 of file munin.py.

00098 
00099     def __getitem__(self, key):
00100         if not key in self._values:
00101             self._values[ key ] = DataSource()
00102         return self._values[ key ]

def munin.Plugin.__setitem__ (   self,
  key,
  value 
)

Definition at line 103 of file munin.py.

00103 
00104     def __setitem__(self, key, value):
00105         self._values[key] = value

def munin.Plugin._print_autoconf (   self) [private]
Running autoconf-mode.

Definition at line 143 of file munin.py.

00143 
00144     def _print_autoconf(self):
00145         """Running autoconf-mode."""
00146         aconf = False
00147 
00148         if hasattr(self, "autoconf"):
00149             if callable(self.autoconf):
00150                 aconf = self.autoconf()
00151             else:
00152                 aconf = self.autoconf
00153 
00154         if bool(aconf):
00155             print "YES"
00156         else:
00157             print "NO"

Here is the caller graph for this function:

def munin.Plugin._print_config (   self) [private]
Print the output needed for setting up the graph - i.e. when the
plugin is run with "config"-argument.

Definition at line 122 of file munin.py.

00122 
00123     def _print_config(self):
00124         """Print the output needed for setting up the graph - i.e. when the
00125         plugin is run with "config"-argument."""
00126         # Print graph_-variables
00127 
00128         for prop in ['title', 'category', 'vlabel', 'info', 'args', 'draw']:
00129             if not prop in self.__dict__:
00130                 continue
00131             if not self.__dict__[ prop ]:
00132                 continue
00133             print "graph_%s %s" % (prop, self.__dict__[ prop ])
00134 
00135         # Print setup for individual lines
00136         for prefix, line in self._values.items():
00137 
00138             # The "label" attribute MUST be defined
00139             assert "label" in line.get_config().keys(), "No 'label' defined."
00140 
00141             for attr, value in line.get_config().items():
00142                 print "%s.%s %s" % (prefix, attr, value)

Here is the caller graph for this function:

def munin.Plugin._print_values (   self) [private]
Print the values for all registered data sources.

Similar to running with "values"-argument.

Definition at line 113 of file munin.py.

00113 
00114     def _print_values(self):
00115         """Print the values for all registered data sources.
00116 
00117         Similar to running with "values"-argument."""
00118         for prefix, line in self._values.items():
00119             value = line.get_value(prefix)
00120             assert type(value) is int
00121             print "%s.value %s" % (prefix, value)

Here is the caller graph for this function:

def munin.Plugin.run (   self,
  force_mode = None 
)
Run the plugin and "do the right thing"^(TM).

Definition at line 158 of file munin.py.

00158 
00159     def run(self, force_mode=None):
00160         """Run the plugin and "do the right thing"^(TM)."""
00161 
00162         mode = force_mode
00163 
00164         if mode == None:
00165             import sys
00166             if len(sys.argv) == 2:
00167                 mode = sys.argv[1]
00168 
00169         if mode == "autoconf":
00170             self._print_autoconf()
00171             return
00172 
00173         if mode == "config":
00174             self._print_config()
00175             return
00176 
00177         self._print_values()

Here is the call graph for this function:


Member Data Documentation

Definition at line 92 of file munin.py.

Definition at line 89 of file munin.py.

Definition at line 87 of file munin.py.

Definition at line 88 of file munin.py.

Definition at line 90 of file munin.py.

Definition at line 85 of file munin.py.

Definition at line 86 of file munin.py.


The documentation for this class was generated from the following file: