· beanstalkd

beanstalkd: Getting the status of the queue

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
stats

current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
cmd-put: 66
...
current-connections: 6
current-producers: 1
current-workers: 1
current-waiting: 1
total-connections: 58
pid: 15622
version: 1.4.6
rusage-utime: 0.000000
rusage-stime: 0.040002
uptime: 22740
binlog-oldest-index: 0
binlog-current-index: 0
binlog-max-size: 10485760

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:

-e
enable interpretation of the backslash-escaped characters listed below

...

\NNN
the character whose ASCII code is NNN (octal)
\\
backslash
\a
alert (BEL)
\b
backspace
\c
suppress trailing newline
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab

We can see how that works with the following example:

$ echo -e "mark\nmark"
mark
mark
$ echo  "mark\nmark"
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

or

# 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:

$ telnet localhost 11300

To see the names of the tubes (queues) where messages get put

list-tubes
OK 14
---
- default

To use that tube

use default
USING DEFAULT

To see if there are any ready jobs

peek-ready
NOT_FOUND

To get the stats for that tube

stats-tube default
OK 253
---
name: default
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
total-jobs: 155
current-using: 9
current-watching: 9
current-waiting: 1
cmd-pause-tube: 0
pause: 0
pause-time-left: 0

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!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket