How can I get the number of queued jobs of a particular type in gearman?

Viewed 20252

I have a number of gearman clients sending a job, say job1.

$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');

It takes, say 10 seconds to process this job. I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that?

7 Answers

For quick checking, I use this bash one-liner:

(echo status ; sleep 0.1) | netcat 127.0.0.1 4730

This opens a connection to a gearman instance running on localhost, and sends the status query. This contains the name and number of jobs on that instance. The information can then be processed with grep/awk/wc etc. for reporting and alerting.

I also do the same with the workers query which shows all connected workers.

(echo workers ; sleep 0.1) | netcat 127.0.0.1 4730

The sleep is to keep the connection open long enough for the reply.

The full list of administrative commands, and what the output means is at http://gearman.org/protocol/. Just search for "Administrative Protocol".

Gearmand has a telnet interface you can query. (the exact details of the protocol can be found on the gearman website - http://gearman.org/?id=protocol )

I used this code here as a starting point for rolling my own. https://github.com/liorbk/php/blob/master/GearmanTelnet.php (this code is perfectly good by itself and you should be able to drop use it out of the box)

It's a less than pretty solution but until someone improves gearman admin interface so you can talk directly via PHP or writes a plugin for it, you are on your own

On Ubuntu 18.04 I have the gearadmin binary installed by default with the gearman package.

gearadmin --help
gearadmin --status can be used instead of the netcat alternative:

gearadmin --status
queue1    334     10      10

And a one liner:
while :; do gearadmin --status; sleep 1; done

Related