A new project I’ve just deployed onto live uses the fast and lightweight beanstalkd work queue. ¬†As part of putting it into live I wanted to get at least some basic monitoring on the beanstalkd daemon. ¬†All my servers run monit for keeping an eye on processes I care about, so that seemed a good place to start.

I had a bit of a look around the interwebs but couldn’t find any examples, so I set about putting something together myself. As it turns out beanstalkd has a nice simple text protocol, detailed in protocol.txt which is included in the source, and monit has the ability to send and expect¬†arbitrary¬†strings to a given port. ¬†For starters I’ve set it up to issue a stats command and check for the expected response which is:

OK \r\n


Adding this to my monit config file for beanstalkd gives me:

check process beanstalkd with pidfile /var/run/beanstalkd.pid start “/etc/init.d/beanstalkd start” stop “/etc/init.d/beanstalkd stop” if failed port 11300 send “stats\r\n” expect “OK [0-9]{1,}\r\n” then alert ```

This is a pretty simple check but at least will enable monit to alert if beanstalkd isn’t listening or is returning garbage.

I think in the long term I’d like nagios to alert on ¬†the current-jobs-delayed and possibly the¬†current-waiting variables reported by the¬†stats-tube command for a given tube, but that is for another day!

Another thought is possibly to have a cacti graph of the total-jobs field, it looks like a always increasing counter, so should be pretty trivial to hook up to cacti.