check_load sample plugin
========================

Invocation
----------

The check_load plugin follows is usually invoked from the command line. To
facilitate testing, we import it as Python module::

>>> from check_load import LoadCheck

Invoking check_load with the `-h` option gives the usual help message::

>>> import nagiosplugin
>>> c = nagiosplugin.Controller(LoadCheck, ['-h'])
>>> print c.format()
Usage: ...
Check the current system load average.
...


Basic plugin usage
------------------

To demonstrate the plugin, we need to ensure repeatable load values. Therefore,
we overwrite the location of `/proc` files with a fake version of `loadavg` to
give repeatable test results::

>>> import tempfile
>>> loadavg = tempfile.NamedTemporaryFile(prefix='loadavg')
>>> print >>loadavg, '0.14 0.91 0.85 1/255 13507\n'
>>> loadavg.flush()
>>> LoadCheck.loadavg = loadavg.name

Invoking `check_load` without parameters, it reports the current load values::

>>> c = nagiosplugin.Controller(LoadCheck, []).run()
>>> print c.format()
LOAD OK - system load average is 0.14 0.91 0.85 ...

Warning and critical thresholds may be specified as usual. `-w` sets the warning
range::

>>> c = nagiosplugin.Controller(LoadCheck, ['-w', '0.1:0.75']).run()
>>> print c.format()
LOAD WARNING - load5 value 0.91 exceeds warning range 0.1:0.75 ...

`-c` sets the critical range. It is ok to specify several values for the 1, 5,
and 15 minutes load average::

>>> c = nagiosplugin.Controller(LoadCheck, ['-c', '2,1,0.5']).run()
>>> print c.format()
LOAD CRITICAL - load15 value 0.85 exceeds critical range 0.5 ...


Performance data
----------------

check_load gives the expected performance data. The 5 and 15 minutes averages
are given as performance expressions in the long output::

>>> c = nagiosplugin.Controller(LoadCheck, []).run()
>>> print c.format()
LOAD OK ... | load1=0.14;1;2;0
| load5=0.91;1;2;0
load15=0.85;1;2;0


Per-CPU load
------------

When the `-r` option is given, the load values are normalized by the number of
cpus. To test this, we first set up a fake `cpuinfo` file which emulates two
cpus::

>>> cpuinfo = tempfile.NamedTemporaryFile(prefix='cpuinfo')
>>> print >>cpuinfo, 'processor : 0\nvendor_id : fake\n\nprocessor : 1\nvendor_id : fake\n'
>>> cpuinfo.flush()
>>> LoadCheck.cpuinfo = cpuinfo.name

Since we have two processors, the load values half the ones reported
previously::

>>> c = nagiosplugin.Controller(LoadCheck, ['-r']).run()
>>> print c.format()
LOAD OK - system load average is 0.07 0.46 0.42 ...

.. vim: set ft=rst:
