-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_multikey
executable file
·103 lines (70 loc) · 1.78 KB
/
redis_multikey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env perl
# -*- perl -*-
=head1 NAME
redis_multikey - Munin plugin to monitor a collection of redis counters
=head1 CONFIGURATION
The counters to monitor are found in a special hash key in redis. So you have
to name the plugin using a symlink of your choice (mycat_counters for example)
and then to configure the mycat_counters with these values:
[mycat_counters]
env.server 127.0.0.1
env.port 6379
env.dbindex 2
env.key munin_mycat
Put it in a file in /etc/munin/plugin-conf.d/ and restart the munin-node.
=head1 USAGE
Link this plugin to /etc/munin/plugins/ and restart the munin-node.
=head1 MAGIC MARKERS
#%# family=contrib
#%# capabilities=
=head1 VERSION
0.1
=head1 AUTHOR
Remi Paulmier
=head1 LICENSE
GPLv2
=cut
use strict;
use warnings;
use lib $ENV{'MUNIN_LIBDIR'};
use Munin::Plugin;
use Redis;
my $VERSION="0.1";
if (! (defined $ENV{'server'} && defined $ENV{'port'} &&
defined $ENV{'dbindex'} && defined $ENV{'key'}) ) {
if ( defined($ARGV[0]) and $ARGV[0] eq "autoconf" ) {
print "no\n";
exit 0;
}
die "missed server or port or dbindex or key.";
} else {
if ( defined($ARGV[0]) and $ARGV[0] eq "autoconf" ) {
print "yes\n";
exit 0;
}
}
my $redis = Redis->new(server => "$ENV{'server'}:$ENV{'port'}" ) or die;
$redis->select($ENV{'dbindex'}) or die;
if ( defined($ARGV[0]) and $ARGV[0] eq "config" ) {
map {
my $cname = $redis->hget($_, 'name');
print <<EOF
multigraph $_
graph_title $cname
graph_category $Munin::Plugin::me
counter.label $_
counter.type GAUGE
counter.draw LINE2
EOF
} $redis->smembers($ENV{'key'});
exit 0;
}
# else dump values
map {
my $cname = $redis->hget($_, 'name');
my $cvalue = $redis->hget($_, 'value');
print <<EOF
multigraph $_
counter.value $cvalue
EOF
} $redis->smembers($ENV{'key'});