Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / redis / resque @ 17f78427

Historique | Voir | Annoter | Télécharger (5,64 ko)

1 decb1715 Andrey Pankov
#!/usr/bin/perl
2
3
#
4
## Copyright (C) 2012 Andrey Pankov <a.pankov@gmail.com>
5
##
6
## This program is free software; you can redistribute it and/or
7
## modify it under the terms of the GNU General Public License
8
## as published by the Free Software Foundation; version 2 dated June,
9
## 1991.
10
##
11
## This program is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
## GNU General Public License for more details.
15
##
16
## You should have received a copy of the GNU General Public License
17
## along with this program; if not, write to the Free Software
18
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
##
20
##
21
## $Log$
22
##
23
## Based on resque monitoring code from https://github.com/caius/redis-munin
24
##
25
## Installation process:
26
##
27
## 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins)
28 cd58f87e Fabien Jakimowicz
## 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 decb1715 Andrey Pankov
## 4. Restart munin-node service
31
32
use strict;
33
use Redis;
34
35
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
36
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
37 cd58f87e Fabien Jakimowicz
my $NAMESPACE = exists $ENV{'namespace'} ? "resque:${ENV{'namespace'}}" : 'resque';
38 decb1715 Andrey Pankov
39
my $server = "$HOST:$PORT";
40
my $r = Redis->new( server => sprintf("%s:%d", $HOST, $PORT) );
41
42
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
43
44
45
$0 =~ s/(.+)resque_//g;
46
my $opt = $0 ? $0 : 'default';
47
48
if ($opt eq 'failed') {
49
    if ($config) {
50
        print "graph_title Resque Failure rate\n";
51 f41b6861 dipohl
        print "graph_category system\n";
52 decb1715 Andrey Pankov
        print "graph_info This graph shows resque jobs that failed\n";
53
        print "graph_args --lower-limit 0\n";
54
        print 'graph_vlabel fails/s\n';
55
56
        print "failed.label Failed per/s\n";
57
        print "failed.type COUNTER\n";
58
    }
59
    else {
60 cd58f87e Fabien Jakimowicz
        my $value = $r->get("${NAMESPACE}:stat:failed") || 0;
61 decb1715 Andrey Pankov
        print "failed.value $value\n";
62
    }
63
}
64
elsif ($opt eq 'queues') {
65
    if ($config) {
66
        print "graph_title Resque queue rates\n";
67 f41b6861 dipohl
        print "graph_category system\n";
68 decb1715 Andrey Pankov
        print "graph_vlabel queue rates/s\n";
69
        print "graph_info This graph monitors the in and out rate of the queues\n";
70
        print "graph_args --lower-limit 0\n";
71
72 cd58f87e Fabien Jakimowicz
        my @queues = $r->smembers( "${NAMESPACE}:queues" );
73 decb1715 Andrey Pankov
        for my $name (@queues) {
74
            $name =~ s/:/_/;
75
76
            print "${name}_pushed.label ${name}_pushed\n";
77
            print "${name}_pushed.type COUNTER\n";
78
79
            print "${name}_finished.label ${name}_finished\n";
80
            print "${name}_finished.type COUNTER\n";
81
        }
82
    }
83
    else {
84 cd58f87e Fabien Jakimowicz
        my @queues = $r->smembers( "${NAMESPACE}:queues" );
85 decb1715 Andrey Pankov
        for my $queue (@queues) {
86
            my $name = $queue;
87
            $name =~ s/:/_/;
88
89 cd58f87e Fabien Jakimowicz
            my $pushed = $r->get("${NAMESPACE}:stat:${queue}:pushed") || 0;
90 decb1715 Andrey Pankov
            print "${name}_pushed.value ${pushed}\n";
91
92 cd58f87e Fabien Jakimowicz
            my $finished = $r->get("${NAMESPACE}:stat:${queue}:finished") || 0;
93 decb1715 Andrey Pankov
            print "${name}_finished.value ${finished}\n";
94
        }
95
    }
96
}
97 cd58f87e Fabien Jakimowicz
elsif ($opt eq 'queues_size') {
98
    if ($config) {
99
        print "graph_title Resque queue current size\n";
100 f41b6861 dipohl
        print "graph_category system\n";
101 cd58f87e Fabien Jakimowicz
        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 17f78427 Lars Kruse
            my $size = $r->llen("${NAMESPACE}:queue:${queue}") || 0;
124
125 cd58f87e Fabien Jakimowicz
	    $total += $size;
126
127
	    print "${name}_size.value ${size}\n";
128
        }
129
130
	print "total.value ${total}\n";
131
    }
132
}
133 decb1715 Andrey Pankov
elsif ($opt eq 'workers_count') {
134
    if ($config) {
135
        print "graph_title Resque Workers Count\n";
136 f41b6861 dipohl
        print "graph_category system\n";
137 decb1715 Andrey Pankov
        print "graph_info This graph shows number of resque workers\n";
138
        print "graph_args --lower-limit 0\n";
139
        print "graph_vlabel workers\n";
140
141
        print "workers_count.label No. of workers\n";
142
        print "workers_count.type COUNTER\n";
143
    }
144
    else {
145 cd58f87e Fabien Jakimowicz
        my @workers = $r->smembers("${NAMESPACE}:workers");
146 decb1715 Andrey Pankov
        print "workers_count.value " . (scalar @workers) . "\n";
147
    }
148
}
149
elsif ($opt eq 'workers_working') {
150
    if ($config) {
151
        print "graph_title Resque Workers in use\n";
152 f41b6861 dipohl
        print "graph_category system\n";
153 decb1715 Andrey Pankov
        print "graph_info This graph shows the \%age of resque workers busy\n";
154
        print "graph_args --lower-limit 0 --upper-limit 100\n";
155
        print "graph_vlabel %\n";
156
157
        print "workers_working.label Workers Busy\n";
158
        print "workers_working.type GAUGE\n";
159
    }
160
    else {
161 cd58f87e Fabien Jakimowicz
        my @workers = $r->smembers("${NAMESPACE}:workers");
162 decb1715 Andrey Pankov
        my $working = 0;
163
        for my $worker (@workers) {
164 cd58f87e Fabien Jakimowicz
            my $value = $r->get("${NAMESPACE}:worker:$worker") || 0;
165 decb1715 Andrey Pankov
            $working++ if $value;
166
        }
167
        my $value = scalar @workers;
168
        if ($value) {
169
            $value = $working * 100 / $value;
170
        }
171
        print "workers_working.value $value\n";
172
    }
173
}