OpenBSD as a monitoring server using Xymon

       706 words, 4 minutes

I’ve been using various monitoring software for a long time now. I always use two kinds of monitoring tools: service checkers, like Nagios, Monit… and metrics graphers, like RRDtool, Cacti, Munin, … I like the Xymon software, AKA Hobbit Monitor, because it can achieve both, uses very low resources and can be customized quite easily.

I used to run it on a FreeBSD virtual machine with ZFS activated. The idea was to compress and deduplicate the RRD data. But in fact, the RRD files weight less than 100MB and ZFS is of no use here. Plus, it seems my 3 virtual disks configuration makes the system lagging a lot ; or is it just the FreeBSD implementation. Anyway, that machine keeps sending timeouts and I can get why. Plus, comparing performance of both VMs, FreeBSD and VMware tools doesn’t seem to use less of my ESXi resources. So it’s time to replace it by some OS that never fails me: OpenBSD.

The installation is going to be done from sources. Because Xymon does not exist in ports (yet) and I’m too lazy right now to write one. So, first of all, the easy part: install OpenBSD. Create the VM, hook up the CD image, boot and follow the Grey Wizard:

# uname -a
OpenBSD xymon.tumfatig.net 5.1 GENERIC#160 i386

Dependencies

Before compiling the Hobbit, you’ll need a few extra packages:

# pkg_add fping gmake openldap-client pcre rrdtool

Yeah, that’s all!

Installation

Get the sources, create a user/group to run the software, configure, compile and install:

# groupadd _xymon
# useradd -d /nonexistent -s /sbin/nologin -c "Xymon Daemon" -g _xymon _xymon

# ftp "http://downloads.sourceforge.net/project/xymon/Xymon/4.3.9/xymon-4.3.9.tar.gz"
# tar xzf xymon-4.3.9.tar.gz
# cd xymon-4.3.9
# MAKE=gmake ./configure.server --rrdlib /usr/X11R6/lib
(...)
Setting up for a Xymon server
(...)
What userid will be running Xymon [xymon] ?
_xymon
(...)
Where do you want the Xymon installation [/nonexistent] ?
/usr/local/xymon
(...)
What group-ID does your webserver use [nobody] ?
www
(...)

# gmake
# gmake install
(...)
Installation complete.

# sudo -u _xymon /usr/local/xymon/server/bin/xymon.sh start
Xymon started

Note the “MAKE=gmake ./configure.server --rrdlib /usr/X11R6/lib”. This forces the use of gmake and helps configure to find every libraries and headers it needs. This solves the following error/warning:

  Checking for RRDtool ...
  Not RRDtool 1.0.x, checking for 1.2.x
  Compiling with RRDtool works OK
  ERROR: Linking with RRDtool fails
  RRDtool include- or library-files not found.
  These are REQUIRED for trend-graph support in Xymon, but Xymon can
  be built without them (e.g. for a network-probe only installation.
  
  RRDtool can be found at http://oss.oetiker.ch/rrdtool/
  If you have RRDtool installed, use the "--rrdinclude DIR" and "--rrdlib DIR"
  options to configure to specify where they are.
  
  Continuing with all trend-graph support DISABLED

Publication

The daemon is to be started at boot:

  # vi /etc/rc.local
  (...)
  [ -x /usr/local/xymon/server/bin/xymon.sh ] && \
  	/usr/bin/sudo -u _xymon /usr/local/xymon/server/bin/xymon.sh start

We’ll use the default Apache server to publish the Web interface:

  # vi /var/www/conf/httpd.conf
  (...)
  LoadModule rewrite_module       /usr/lib/apache/modules/mod_rewrite.so
  (...)
  AddHandler cgi-script .sh
  (...)
  Include /usr/local/xymon/server/etc/xymon-apache.conf
  
  # htpasswd -c /usr/local/xymon/server/etc/xymonpasswd username
  
  # vi /etc/rc.conf.local
  (...)
  httpd_flags="-u"
  
  # /etc/rc.d/httpd start    
  httpd(ok)

Finally, we don’t want the logs to grow forever:

  # crontab -e
  (...)
  # Xymon logs
  0 0 * * * for LOGFILE in /var/log/xymon/*.log; do         \
  /bin/echo "$LOGFILE _xymon:_xymon 644 3 720 24 Z"; done | \
   /usr/bin/newsyslog -f - ; /usr/bin/sudo -u _xymon        \
  /usr/local/xymon/server/bin/xymon.sh rotate

Data migration

I wanted to keep the RRD data I already had. RRD files can be copied and re-used from one machine to another… expect if they’re not using the same architecture. In my case, I had to migrate from FreeBSD/amd64 to OpenBSD/i386.

On the source server, dump the RRD data in XML files:

  # cd /usr/local/www/xymon/data/rrd
  # find . -type f -name "*.rrd" -exec sh          \
    -c 'RRDFILE={}; DUMPFILE=${RRDFILE%.rrd}.xml;  \
    rrdtool dump --no-header $RRDFILE > $DUMPFILE'
  # tar cpzf rrd.tar.bz2 `find . -type f -name "*.xml" | xargs`

Note the “–no-header” flags that is required to downgrade from RRDtool 1.4.5 to 1.2.30. On the destination server, convert XML files back into RRD data:

  # cd /usr/local/xymon/data/rrd
  
  # sudo -u _xymon tar xzf rrd.tar.bz2
  # sudo -u _xymon find . -type f -name "*.xml" -exec sh -c 'DUMPFILE={}; \
    RRDFILE=${DUMPFILE%.xml}.rrd; rrdtool restore -f $DUMPFILE $RRDFILE' \;

Ready to Rock’N’Roll!