Révision cd58f87e
[resque] allow a namespace to be defined as an environment variable
[resque] add a graph to monitor queue size
| plugins/redis/resque | ||
|---|---|---|
| 25 | 25 |
## Installation process: |
| 26 | 26 |
## |
| 27 | 27 |
## 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins) |
| 28 |
## 2. Create 4 symlinks at the directory that is used by munin for plugins detection (e.g. /etc/munin/plugins): resque_failed, resque_queues, resque_workers_count, resque_workers_working
|
|
| 29 |
## 3. Edit plugin-conf.d/munin-node if it is needed (env.host and env.port variables are accepted) |
|
| 28 |
## 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
|
|
| 29 |
## 3. Edit plugin-conf.d/munin-node if it is needed (env.namespace, env.host and env.port variables are accepted)
|
|
| 30 | 30 |
## 4. Restart munin-node service |
| 31 | 31 |
|
| 32 | 32 |
use strict; |
| ... | ... | |
| 34 | 34 |
|
| 35 | 35 |
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
|
| 36 | 36 |
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
|
| 37 |
my $NAMESPACE = exists $ENV{'namespace'} ? "resque:${ENV{'namespace'}}" : 'resque';
|
|
| 37 | 38 |
|
| 38 | 39 |
my $server = "$HOST:$PORT"; |
| 39 | 40 |
my $r = Redis->new( server => sprintf("%s:%d", $HOST, $PORT) );
|
| ... | ... | |
| 56 | 57 |
print "failed.type COUNTER\n"; |
| 57 | 58 |
} |
| 58 | 59 |
else {
|
| 59 |
my $value = $r->get('resque:stat:failed') || 0;
|
|
| 60 |
my $value = $r->get("${NAMESPACE}:stat:failed") || 0;
|
|
| 60 | 61 |
print "failed.value $value\n"; |
| 61 | 62 |
} |
| 62 | 63 |
} |
| ... | ... | |
| 68 | 69 |
print "graph_info This graph monitors the in and out rate of the queues\n"; |
| 69 | 70 |
print "graph_args --lower-limit 0\n"; |
| 70 | 71 |
|
| 71 |
my @queues = $r->smembers( 'resque:queues' );
|
|
| 72 |
my @queues = $r->smembers( "${NAMESPACE}:queues" );
|
|
| 72 | 73 |
for my $name (@queues) {
|
| 73 | 74 |
$name =~ s/:/_/; |
| 74 | 75 |
|
| ... | ... | |
| 80 | 81 |
} |
| 81 | 82 |
} |
| 82 | 83 |
else {
|
| 83 |
my @queues = $r->smembers( 'resque:queues' );
|
|
| 84 |
my @queues = $r->smembers( "${NAMESPACE}:queues" );
|
|
| 84 | 85 |
for my $queue (@queues) {
|
| 85 | 86 |
my $name = $queue; |
| 86 | 87 |
$name =~ s/:/_/; |
| 87 | 88 |
|
| 88 |
my $pushed = $r->get("resque:stat:${queue}:pushed") || 0;
|
|
| 89 |
my $pushed = $r->get("${NAMESPACE}:stat:${queue}:pushed") || 0;
|
|
| 89 | 90 |
print "${name}_pushed.value ${pushed}\n";
|
| 90 | 91 |
|
| 91 |
my $finished = $r->get("resque:stat:${queue}:finished") || 0;
|
|
| 92 |
my $finished = $r->get("${NAMESPACE}:stat:${queue}:finished") || 0;
|
|
| 92 | 93 |
print "${name}_finished.value ${finished}\n";
|
| 93 | 94 |
} |
| 94 | 95 |
} |
| 95 | 96 |
} |
| 97 |
elsif ($opt eq 'queues_size') {
|
|
| 98 |
if ($config) {
|
|
| 99 |
print "graph_title Resque queue current size\n"; |
|
| 100 |
print "graph_category Resque\n"; |
|
| 101 |
print "graph_vlabel queue size\n"; |
|
| 102 |
print "graph_info This graph monitors the current queues size\n"; |
|
| 103 |
print "graph_args --lower-limit 0\n"; |
|
| 104 |
|
|
| 105 |
my @queues = $r->smembers( "${NAMESPACE}:queues" );
|
|
| 106 |
for my $name (@queues) {
|
|
| 107 |
$name =~ s/:/_/; |
|
| 108 |
|
|
| 109 |
print "${name}_size.label ${name}_size\n";
|
|
| 110 |
print "${name}_size.type GAUGE\n";
|
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
print "total.label total\n"; |
|
| 114 |
print "total.type GAUGE\n"; |
|
| 115 |
} |
|
| 116 |
else {
|
|
| 117 |
my @queues = $r->smembers( "${NAMESPACE}:queues" );
|
|
| 118 |
my $total = 0; |
|
| 119 |
for my $queue (@queues) {
|
|
| 120 |
my $name = $queue; |
|
| 121 |
$name =~ s/:/_/; |
|
| 122 |
|
|
| 123 |
my $size = $r->llen("${NAMESPACE}:queue:${queue}") || 0;
|
|
| 124 |
|
|
| 125 |
$total += $size; |
|
| 126 |
|
|
| 127 |
print "${name}_size.value ${size}\n";
|
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
print "total.value ${total}\n";
|
|
| 131 |
} |
|
| 132 |
} |
|
| 96 | 133 |
elsif ($opt eq 'workers_count') {
|
| 97 | 134 |
if ($config) {
|
| 98 | 135 |
print "graph_title Resque Workers Count\n"; |
| ... | ... | |
| 105 | 142 |
print "workers_count.type COUNTER\n"; |
| 106 | 143 |
} |
| 107 | 144 |
else {
|
| 108 |
my @workers = $r->smembers('resque:workers');
|
|
| 145 |
my @workers = $r->smembers("${NAMESPACE}:workers");
|
|
| 109 | 146 |
print "workers_count.value " . (scalar @workers) . "\n"; |
| 110 | 147 |
} |
| 111 | 148 |
} |
| ... | ... | |
| 121 | 158 |
print "workers_working.type GAUGE\n"; |
| 122 | 159 |
} |
| 123 | 160 |
else {
|
| 124 |
my @workers = $r->smembers('resque:workers');
|
|
| 161 |
my @workers = $r->smembers("${NAMESPACE}:workers");
|
|
| 125 | 162 |
my $working = 0; |
| 126 | 163 |
for my $worker (@workers) {
|
| 127 |
my $value = $r->get("worker:$worker") || 0;
|
|
| 164 |
my $value = $r->get("${NAMESPACE}:worker:$worker") || 0;
|
|
| 128 | 165 |
$working++ if $value; |
| 129 | 166 |
} |
| 130 | 167 |
my $value = scalar @workers; |
Formats disponibles : Unified diff