I still have my brown Acquia T-shirt that was distributed at the March, 2009 Washington DC DurpalCon. On the back it says “Free as in beer”. Well, the free bit still applies to Acquia Drupal, and the various stacks which are useful for various operating systems and environments to a lot of people. But now Acquia is mumbling in their beer: no more freebie community style accounts, you gotta start paying for site monitoring via the Acquia Network once the initial 30 day trial period ends. OK, it does include goodies like Acquia search, and other stuff. But to get a solution that is truly free as in beer, and a richer solution at that, it’s clearly Nagios time for us dogs.
This is a detailed howto article, but you can skip the parts that you don’t need easily, and it will get you up and running with an enviable Nagios Drupal Monitoring station. Just jump in wherever:
- What is Nagios?
- Setting up the Nagios monitoring application.
- Setting up the Nagios monitoring module (Thanks kbahey — Khalid Baheyeldin of 2bits.com)
- Enjoy your free Drupal sites monitoring dashboard!
- Enjoy receving Drupal site Nagios alerts in your mail for free!
- What’s next? Roll your own…
- Enterprise level search: Apache Solr Search Integration explored in details along with other options (Sphinx integration , and Search Lucene API and related modules
- Spam blocking server alternatives
- Centralized administrative task management
- Centralized software deployment and update alternatives, especially with drush and the Aegir Hosting System.
What is Nagios?
“So what are the sorts of things Nagios can do? Nagios can do much more than this, but nevertheless here’s a list of common things that Nagios is used for.
Check to see if a server is up and running
Notify you if a server is down (by email/pager/SMS)
Check to see if a service is running (mail, http, pop, ssh)
Check to see if a process (or Windows service) is running
Gather performance statistics on a server
Allow specific alerts to only go to particular groups/individuals
- Get reports of downtime on your servers”
from “What is Nagios”, The Nagios Book
As independent Drupal developers our own server and sites infrastructure, even together with all the hosted production sites belonging to our clients, is no match for a large corporation’s IT infrastructure. But we still need to monitor them, and so a system like Nagios, which is open source software and published under the GPL license (http://www.nagios.org/about/features), and, erm, free as in beer, is looking pretty good right now. See http://www.nagios.org/about
Setting up the Nagios monitoring application.
OK, first of all, we are talking about server environments and shared hosting is not convered in this article. The Drupal sites BEING monitored can be on shared hosts, no problem there, of course. I simply don’t cover setting up the Nagios monitoring application itself on shared hosts. So we are assuming a VPS or Dedicated server environment, where you have root access. But, hey, if you can install Drupal from a tarball you can install Nagios . ’nuff said.
Check out the Nagios Quickstart Installation Guides for your own particular environment flavor. Also, here are a couple of Ubuntu examples from my own recent experience:
Example: Installing Nagios as an Ubuntu package
About a year ago I was beginning work on a development server, and installed Nagios on an Ubuntu 8.10 Server edition. You can find detailed instructions on installation and configuration here: https://awebfactory.com.ar/node/345#installnagios
Example: Installing the latest version from source on Ubuntu Hardy
[Skip to the next section on setting up the Drupal Nagios monitoring module]
I basically followed the instructions found at http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html and reflected in http://www.ubuntugeek.com/nagios-network-monitoring-system-setup-in-ubuntu.html. Please leave a comment here if you encounter any difficulty.
As advertised, I ended up with:
- Nagios and the plugins will be installed underneath /usr/local/nagios
- Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
- The Nagios web interface will be accessible at http://localhost/nagios/
Useful command-line Nagios commands:
To check the configuration files for warnings and errors, I did the following:
# [code]/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg[/code]
Starting, stopping, restarting nagios from the command-line (after changing configuration, for example):
# [code]/etc/init.d/nagios start [/code]
# [code]/etc/init.d/nagios stop [/code]
# [code]/etc/init.d/nagios restart [/code]
Setting up the Nagios monitoring module (Thanks kbahey — Khalid Baheyeldin of 2bits.com).
Almost as soon as I installed Nagios for the first time about a year ago and was wondering to myself, “OK, I got myself a heartbeat, now what?”, Khalid (kbahey) blogged about his recently developed Drupal Nagios monitoring module, and I was so happy I promised him I would try it. Well, better late than never, so here goes!
Download the module http://drupal.org/project/nagios to each of the client Drupal sites, as well as the Nagios server site also (for the included Nagios plugin, details on this in a moment).
Read the author’s disclaimers found in the README.txt file, especially on security… (the unique identifier security enhancer works well, I recommend that) and follow the instructions found there.
I created my unique identifer on a linux command line specifying a string composed of, for example, items like MAC numbers, a random number and a datestamp, and did something like:
[code]$ echo "xxxxx string goes here *****" | md5sum[/code]
[code] xxxxxxxxxxxxxxxxxxxxxxxxxx[/code]
and copied the result.
After installing and enabling the module as usual, I headed over to Administer > Settings > Nagios monitoring, and entered the ID created in previous step.
In general, I followed the instructions in README.txt
I then mosied over to the Nagios server site. I copied the check_drupal script found in the nagios-plugin sub-directory to the Nagios plugins directory. Where this is depends on your nagios install. The module author speaks of /usr/lib/nagios/plugins but in my case (compiled from source together with plugins following the Nagios quick start guide) it was /usr/local/nagios/libexec.
I double-checked to make sure it had execute permissions and did a:
# [code]chown nagios:nagios check_drupal[/code]
in line with other plugins I knew were already working (like check_ping).
Since I am working with Nagios 3.x on my server (latest stable 3.2.0 at my time of writing), I next edited the commands.cfg file in the /usr/local/nagios/etc/objects directory, adding the following (make sure the command_line path is accurate):
################################################################################
# Command for Drupal Nagios monitoring module http://drupal.org/project/nagios
################################################################################
define command{
command_name check_drupal
command_line /usr/local/nagios/libexec/check_drupal -H $HOSTADDRESS$ -U $ARG1$ -t $ARG2$
}
Then, following the examples in the nagios sample configuration files I went ahead and added the Drupal site host(s), hostgroup and services info into a single drupal.cfg file in the objects directory (/usr/local/nagios/etc/objects) instead of separately following steps 3 and 4 from the Drupal module README file.
I ended up with the following
/usr/local/nagios/etc/objects/drupal.cfg
file (info changed to protect the guilty):
# cat drupal.cfg
###############################################################################
# drupal.cfg - Configuration file for monitoring drupal site hosts
#
###############################################################################
###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################
define host{
use linux-server ; Name of host template to use
host_name awebfactory.com.ar
alias awebfactory.com.ar
}
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name drupal-servers ; The name of the hostgroup
alias Drupal Servers ; Long name of the group
members awebfactory.com.ar ; Comma separated list of hosts that belong to this group
}
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
define service{
hostgroup_name drupal-servers
service_description DRUPAL
check_command check_drupal!unique identifier!2
use generic-service
notification_interval 0 ; set > 0 if you want to be renotified
}
Be sure to replace “unique identifier” with your… unique identifier (discussed above). The exclamation marks are simply Nagios speak to separate the paramaters used to invoke the plugin.
After having created the configuration file in this way, I then enabled it in:
/usr/local/nagios/etc/nagios.cfg
by adding the following two lines just under the localhost.cfg specification, ending up as follows:
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Definitions for monitoring Drupal servers
cfg_file=/usr/local/nagios/etc/objects/drupal.cfg
Now to check the sanity of all the new configuration setup and finally to restart the nagios service itself.
To carry out this check for warnings and errors, I did the following:
# [code]/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg[/code]
A bunch of highly useful info scrolled by, and then I saw:
Total Warnings: 0
Total Errors: 0
Which is what I wanted to see, of course!
But does it work? First restart the nagios service:
# [code]/etc/init.d/nagios restart[/code]
and then point your browser at http://example.com/nagios .
If you have difficulties with the Drupal plugin, you can execute drupal_check from the command_line:
/usr/local/nagios/libexec # ./check_drupal -U xxxxxxxxx
Comments? Did people get this working?
Enjoy your free Drupal sites Nagios monitoring dashboard!
Pointing your browser at the Nagios monitoring application (in my install it was something like http://example.com/nagios), and clicking on Services should yield a screen similar to the following (in this case the Drupal service is grumbling about Date Popup JQuery UI requirements :
So I installed the JQuery UI module and library, and everything was blessed:
Enjoy receving Drupal site Nagios alerts in your mail for free!
Meanwhile, I had taken care to install mailx in my system and correct the Nagios configuration files accordingly, in order to get those annoying but life-saving emails for alerts and recoveries!
I did the following from the command line on the Nagios server:
# apt-get install mailx
# which mailx
/usr/bin/mailx
Armed with the knowledge of how to invoke mailx, I went to the appropriate directory and edited commands.cfg so that the right mail sending utility would be invoked (I replaced /usr/bin/mail with /usr/bin/mailx wherever it occurred):
cd /usr/local/nagios/etc/objects/
vi commands.cfg
I restarted Nagios for the changes to take effect:
/etc/init.d/nagios restart
And lo and behold, for annoying alerts started rolling into my email account (since I am the nagioadmin contact: see contacts.cfg in the objects directory):
The text of the mail reads as follows:
OK! We’re good to go. Now I can add additional host definitions in /usr/local/nagios/etc/objects/drupal.cfg
What’s next? Roll your own…
- Enterprise level search: Apache Solr Search Integration explored in details along with other options (Sphinx integration , and Search Lucene API and related modules
- Spam blocking server alternatives
- Centralized administrative task management
- Centralized software deployment and update alternatives, especially with drush and the Aegir Hosting System.
- What?