Last update: 2007-02-12

// C O N T R O L - A L T - D E L . O R G

"Fate strikes down the strong man, Everyone weep with me " - O Fortuna
NAVIGATION>>
HOME PICS ABOUT NEWS CODE BOOKS MAIL
:: CODE
The three chief virtues of a programmer are: Laziness, Impatience and Hubris
-- Larry Wall
CONTACT
:. NPDaemon - Nagios Performance data daemon

NPDaemon is a daemon that connects to the performance data pipe of Nagios and extracts peformance data, making it available on a socket-based server for external applications to poll.

Example applications are using the daemon along with Cacti to graph data collected. I'll write up a more comprehensive guide later.

Code: Mark Steele

Ideas, debugging, documentation: Thomas Guyot-Sionnest

:. Document conventions

Commands to run use the Courier New font and are highlighted in orange:

/path/to/a/command/to/run --options

 


File contents are always displayed within a text area field:

 

(sorry firefox folks, copy-paste button only works with IE)


Explanations use Arial – This text.

:. Assumptions
  • Working Linux server
  • You need to be root to install these packages
  • Linux kernel with epoll() recommended
  • Perl 5.6+ (tested with 5.8)
  • Libevent installed and working properly. I highly recommend that you ensure that libevent can use the epoll() syscall mechanism.
  • Daemontools installed
  • Nagios installed and working.
:. Nagios configuration

Edit Nagios' config file, and add the following directives:


This will instruct nagios to start writing service performance data to a FIFO.


:. Protocol specification

The following commands are understood by the daemon:



INDEX <hostname>

Returns a list of all the services for a particular host. The format returned is :

service1\tservice2\tserviceN\n (\t: tab)

 

QUERY <hostname> <service>

Returns a series of counters and data values for the specified service. The format returned is:

counter1:value1 counter2:value2 counterN:valueN\n


GET <hostname> <service> <counter>

Returns the value of the specified counter. The format returned is:

value\n


DUMP

Returns the data contained in the data cache. The format returned is from the freeze() function of Perl's Storable module.


CLEAR

Erases all data held in memory. Returns:

OK\n


Example:

GET <jupiter.mydomain.com> <HTTP> <ResponseTime>

:. Installation

Download and install prerequisite perl modules.

cpan> install Event::Lib Storable Curses::UI


Edit /usr/sbin/NPDaemon :




Edit /usr/bin/NPDaemon_admin :



Create a runscript for Daemontools:

mkdir /etc/NPDaemon
cat <<EOF >/etc/NPDaemon/run
#!/bin/sh
exec > /dev/null
exec 2>&1
exec /usr/sbin/NPDaemon
EOF
chmod +x /etc/NPDaemon/run

 

:. TODO

Write some more documentation on how to use this. Should be forthcomming.

Make IP and port configurable (defaults to 127.0.0.1 port 1111)

Probably wouldn't be a bad idea to setuid to a different user on start-up.

The admin client probably needs lots of debugging.

© copyright 2007 Mark Steele