For the last few days Jason and I have been porting a few of our applications across to a new puppet setup and one thing we needed to do was check that messages were passing through beanstalkd correctly.
We initially had the idea that it wasn’t configured correctly so Paul showed us a way of checking whether that was the case by connecting to the port it runs on like so:
$ telnet localhost 11300
The way we’d setup our beanstalks consumer, if it wasn’t able to process a message correctly we put the message back on the queue in a ‘buried’ state so we’d see a number greater than 0 for the ‘current-jobs-buried’ property.
I was already curious how we’d go about writing a one liner to get those stats using netcat and after a bit of fiddling to force the new line character to be sent properly I ended up with the following:
$ echo -e "stats\r\n" | nc localhost 11300
The key is the ‘-e’ flag which I may well have written about before but had forgotten all about:
enable interpretation of the backslash-escaped characters listed below
the character whose ASCII code is NNN (octal)
suppress trailing newline
We can see how that works with the following example:
$ echo -e "mark\nmark"
$ echo "mark\nmark"
Alternatively we can pass either the ‘-c’ or ‘-C’ flag depending on our version of netcat and a CRLF/newline will be sent as the line ending:
# netcat-openbsd version
$ echo "stats" | nc -C localhost 11300
# one on Mac OS X by default
$ echo "stats" | nc -c localhost 11300
Going back to beanstalkd – there is actually a pretty good document explaining all the different commands that you can send to it, most of which I haven’t tried yet!
I have come across some useful ones though:
To see the names of the tubes (queues) where messages get put
To use that tube
To see if there are any ready jobs
To get the stats for that tube
I came across beanstalk-tools which contains a bunch of tools for working with beanstalks but since our use is sporadic sending the commands over TCP every now and then will probably do!