2012-03-14 12:56:33 +01:00
#!/usr/bin/perl
#
## Copyright (C) 2012 Andrey Pankov <a.pankov@gmail.com>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; version 2 dated June,
## 1991.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
##
## $Log$
##
## Based on resque monitoring code from https://github.com/caius/redis-munin
##
## Installation process:
##
## 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins)
2012-06-27 18:31:37 +02:00
## 2. Create 5 symlinks at the directory that is used by munin for plugins detection (e.g. /etc/munin/plugins): resque_failed, resque_queues, resque_queues_size, resque_workers_count, resque_workers_working
## 3. Edit plugin-conf.d/munin-node if it is needed (env.namespace, env.host and env.port variables are accepted)
2012-03-14 12:56:33 +01:00
## 4. Restart munin-node service
use strict;
use Redis;
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
2012-06-27 18:31:37 +02:00
my $NAMESPACE = exists $ENV{'namespace'} ? "resque:${ENV{'namespace'}}" : 'resque';
2012-03-14 12:56:33 +01:00
my $server = "$HOST:$PORT";
my $r = Redis->new( server => sprintf("%s:%d", $HOST, $PORT) );
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
$0 =~ s/(.+)resque_//g;
my $opt = $0 ? $0 : 'default';
if ($opt eq 'failed') {
if ($config) {
print "graph_title Resque Failure rate\n";
print "graph_category Resque\n";
print "graph_info This graph shows resque jobs that failed\n";
print "graph_args --lower-limit 0\n";
print 'graph_vlabel fails/s\n';
print "failed.label Failed per/s\n";
print "failed.type COUNTER\n";
}
else {
2012-06-27 18:31:37 +02:00
my $value = $r->get("${NAMESPACE}:stat:failed") || 0;
2012-03-14 12:56:33 +01:00
print "failed.value $value\n";
}
}
elsif ($opt eq 'queues') {
if ($config) {
print "graph_title Resque queue rates\n";
print "graph_category Resque\n";
print "graph_vlabel queue rates/s\n";
print "graph_info This graph monitors the in and out rate of the queues\n";
print "graph_args --lower-limit 0\n";
2012-06-27 18:31:37 +02:00
my @queues = $r->smembers( "${NAMESPACE}:queues" );
2012-03-14 12:56:33 +01:00
for my $name (@queues) {
$name =~ s/:/_/;
print "${name}_pushed.label ${name}_pushed\n";
print "${name}_pushed.type COUNTER\n";
print "${name}_finished.label ${name}_finished\n";
print "${name}_finished.type COUNTER\n";
}
}
else {
2012-06-27 18:31:37 +02:00
my @queues = $r->smembers( "${NAMESPACE}:queues" );
2012-03-14 12:56:33 +01:00
for my $queue (@queues) {
my $name = $queue;
$name =~ s/:/_/;
2012-06-27 18:31:37 +02:00
my $pushed = $r->get("${NAMESPACE}:stat:${queue}:pushed") || 0;
2012-03-14 12:56:33 +01:00
print "${name}_pushed.value ${pushed}\n";
2012-06-27 18:31:37 +02:00
my $finished = $r->get("${NAMESPACE}:stat:${queue}:finished") || 0;
2012-03-14 12:56:33 +01:00
print "${name}_finished.value ${finished}\n";
}
}
}
2012-06-27 18:31:37 +02:00
elsif ($opt eq 'queues_size') {
if ($config) {
print "graph_title Resque queue current size\n";
print "graph_category Resque\n";
print "graph_vlabel queue size\n";
print "graph_info This graph monitors the current queues size\n";
print "graph_args --lower-limit 0\n";
my @queues = $r->smembers( "${NAMESPACE}:queues" );
for my $name (@queues) {
$name =~ s/:/_/;
print "${name}_size.label ${name}_size\n";
print "${name}_size.type GAUGE\n";
}
print "total.label total\n";
print "total.type GAUGE\n";
}
else {
my @queues = $r->smembers( "${NAMESPACE}:queues" );
my $total = 0;
for my $queue (@queues) {
my $name = $queue;
$name =~ s/:/_/;
my $size = $r->llen("${NAMESPACE}:queue:${queue}") || 0;
$total += $size;
print "${name}_size.value ${size}\n";
}
print "total.value ${total}\n";
}
}
2012-03-14 12:56:33 +01:00
elsif ($opt eq 'workers_count') {
if ($config) {
print "graph_title Resque Workers Count\n";
print "graph_category Resque\n";
print "graph_info This graph shows number of resque workers\n";
print "graph_args --lower-limit 0\n";
print "graph_vlabel workers\n";
print "workers_count.label No. of workers\n";
print "workers_count.type COUNTER\n";
}
else {
2012-06-27 18:31:37 +02:00
my @workers = $r->smembers("${NAMESPACE}:workers");
2012-03-14 12:56:33 +01:00
print "workers_count.value " . (scalar @workers) . "\n";
}
}
elsif ($opt eq 'workers_working') {
if ($config) {
print "graph_title Resque Workers in use\n";
print "graph_category Resque\n";
print "graph_info This graph shows the \%age of resque workers busy\n";
print "graph_args --lower-limit 0 --upper-limit 100\n";
print "graph_vlabel %\n";
print "workers_working.label Workers Busy\n";
print "workers_working.type GAUGE\n";
}
else {
2012-06-27 18:31:37 +02:00
my @workers = $r->smembers("${NAMESPACE}:workers");
2012-03-14 12:56:33 +01:00
my $working = 0;
for my $worker (@workers) {
2012-06-27 18:31:37 +02:00
my $value = $r->get("${NAMESPACE}:worker:$worker") || 0;
2012-03-14 12:56:33 +01:00
$working++ if $value;
}
my $value = scalar @workers;
if ($value) {
$value = $working * 100 / $value;
}
print "workers_working.value $value\n";
}
}