monitoring ubuntu web servers with nagios3

I have chosen Nagios to keep track of the anyhosting.com network. There are many alternatives (some I have explored and some not yet), what I like about Nagios:

  • I’ve been using it for a long time; familiarity
  • very simple/powerful plugin system
  • tons of users, so lots of examples and plugins already available

Nagios version 3 is provided in the Ubuntu repositories, and is quite simple to install:

root@admin:~# apt-get install nagios3

The default config comes set up to monitor a set of services on localhost; I don’t really like the default Ubuntu/Debian setup of having one config file per host/service/etc, so on the master I’ve replaced the config file structure:

root@admin:/etc/nagios3/conf.d# cd /etc/nagios3/conf.d/
root@admin:/etc/nagios3/conf.d# ls
contacts.cfg  extinfo.cfg  groups.cfg  hosts.cfg  services.cfg 
timeperiods.cfg

groups.conf contains the set of server types that I care about:

# A list of your web servers
define hostgroup {
  hostgroup_name  http-servers
  alias           HTTP servers
  members         localhost
}

# A list of your mysql servers
define hostgroup {
  hostgroup_name  mysql-servers
  alias           MySQL servers
}

# A list of your VHosts
define hostgroup {
  hostgroup_name  http-vhosts
  alias           Virtual Host HTTP servers
}

Note that the “http-servers” can define “members” (localhost in this case), however in general I do not add members in this file but instead in the hosts.cfg:

define host {
  host_name   anyhosting1
  address     1.2.3.4
  use         generic-host
  hostgroups  http-servers
}

define host {
  host_name   example.com
  address     1.2.3.4
  use         generic-host
  hostgroups  http-vhosts
}

Note the “hostgroups” line; anyhosting1 is the physical server (this monitor is really checking on the reverse proxy), and example.com is a vhost (which is really proxying to a user running Apache for the “example.com” domain). These two checks make sure that the whole system is working and proxying correctly.

Finally, services.cfg brings it all together by defining which groups should run which services:

# check that web services are running
define service {
  hostgroup_name         http-servers
  service_description    HTTP
  check_command          check_http
  use                    generic-service
  notification_interval  0 # set > 0 if you want to be renotified
}

define service {
  hostgroup_name         http-vhosts
  service_description    Virtual Host HTTP
  check_command          check_httpname
  use                    generic-service
  notification_interval  0 # set > 0 if you want to be renotified
}

The Ubuntu nagios-plugins package (which by default is installed along with the nagios3 package) contains plugins that can intelligently check MySQL databases, disk space, load average, etc. By default these only work on the local machine, but these can be made to run on remote machines by installing the nagios-nrpe-server package. I will cover this further in a future blog post.

Leave a Reply