Donnerstag, 20. Dezember 2012

Monitoring symfony2/swiftmailer spooling queue

If you want to monitor your email spooling queue and you are using symfony2 with swiftmailer, and if you are using Nagios or Icinga for your monitoring, I got a christmas present for you! Of course this only works when you use file spooling. Memory spooling sends mails on the end of each request, so there is not much to monitor.

I created a small shell script with no dependencies other than basic Linux tools (like find and wc) which counts the number of mails in the queue and let you thereby monitor them with Nagios/Icinga. For my example I'll use check_nrpe to execute the plugin remote on the application server.

First, here is the script. You need to save it executeable in your plugin directory on the remote machine, which in my case is /usr/lib/nagios/plugins. I saved it as check_spool:

Next you need to configure the plugin on your remote machine, adding the command to the nrpe commands in your nrpe.cfg:

command[check_spool]=/usr/lib/nagios/plugins/check_spool "/path/to/swiftmailer/spool" -w 5 -c 50

Mind the /path/to/swiftmailer/spool which should be replaced by the directory you keep your spooled files in. The -w and -c options are the Nagios/Icinga standard parameters for warning and critical threshhold. With this command registered, you can restart your nrpe server and add the check to the monitoring server:

define service{
    use                             generic-service
    host_name                       hostname
    service_description             Swiftmailer Spooling Queue
    check_command                   check_nrpe_1arg!check_spool

You can place this anywhere in your icinga/objects folder. Change the hostname for your defined hostname and restart Icinga. Maybe you need to change the check_nrpe_1arg for check_nrpe, depending on your Nagios/Icinga version.

Now, looking in your Nagios/Icinga frontend, you should see the service running without issues. To troubleshoot, you can execute the script on the remote server manually and see if any errors are thrown. Doublecheck the command in your nrpe.cfg if parameters are correct. If NRPE is working, this command should be no exception.

Happy monitoring!

Keine Kommentare:

Kommentar veröffentlichen