Révision 016400bd
Updating redis plugin
Added autoconf and suggest capabilities, added additional graphs,
and tweaked some existing graphs in order to attempt to meet best
practices
| plugins/redis/redis_ | ||
|---|---|---|
| 28 | 28 |
## 2. Create 3 symlinks at the directory that us used by munin for plugins detection (e.g. /etc/munin/plugins): redis_connected_clients, redis_per_sec and and redis_used_memory |
| 29 | 29 |
## 3. Edit plugin-conf.d/munin-node if it is needed (env.host and env.port variables are accepted; set env.password for password protected Redis server) |
| 30 | 30 |
## 4. Restart munin-node service |
| 31 |
## |
|
| 32 |
## Magic Markers |
|
| 33 |
#%# family=auto |
|
| 34 |
#%# capabilities=autoconf suggest |
|
| 31 | 35 |
|
| 32 | 36 |
use strict; |
| 33 | 37 |
use IO::Socket::INET; |
| ... | ... | |
| 37 | 41 |
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
|
| 38 | 42 |
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef;
|
| 39 | 43 |
|
| 40 |
my $server = "$HOST:$PORT"; |
|
| 41 |
my $sock = IO::Socket::INET->new( |
|
| 42 |
PeerAddr => $server, |
|
| 43 |
Proto => 'tcp' |
|
| 44 |
); |
|
| 45 |
|
|
| 46 |
if ( defined( $PASSWORD ) ) {
|
|
| 47 |
print $sock "AUTH ", $PASSWORD, "\r\n"; |
|
| 48 |
my $result = <$sock> || die "can't read socket: $!"; |
|
| 44 |
my $sock = &get_conn(); |
|
| 45 |
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" ); |
|
| 46 |
my $autoconf = ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ); |
|
| 47 |
if ( $autoconf ) {
|
|
| 48 |
if ( defined( $sock ) ) {
|
|
| 49 |
print "yes\n"; |
|
| 50 |
exit 0; |
|
| 51 |
} else {
|
|
| 52 |
print "no (unable to connect to $HOST\[:$PORT\])\n"; |
|
| 53 |
exit 0; |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
my $suggest = ( defined $ARGV[0] and $ARGV[0] eq "suggest" ); |
|
| 57 |
if ( $suggest ) {
|
|
| 58 |
if ( defined( $sock ) ) {
|
|
| 59 |
my @plugins = ('connected_clients', 'key_ratio', 'keys_per_sec', 'per_sec', 'used_keys', 'used_memory');
|
|
| 60 |
foreach my $plugin (@plugins) {
|
|
| 61 |
print "$plugin\n"; |
|
| 62 |
} |
|
| 63 |
exit 0; |
|
| 64 |
} else {
|
|
| 65 |
print "no (unable to connect to $HOST\[:$PORT\])\n"; |
|
| 66 |
exit 0; |
|
| 67 |
} |
|
| 49 | 68 |
} |
| 50 | 69 |
|
| 51 | 70 |
print $sock "INFO\r\n"; |
| ... | ... | |
| 61 | 80 |
} |
| 62 | 81 |
close ($sock); |
| 63 | 82 |
|
| 64 |
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" ); |
|
| 65 |
|
|
| 66 |
|
|
| 67 | 83 |
$0 =~ s/(.+)redis_//g; |
| 68 | 84 |
|
| 69 | 85 |
switch ($0) {
|
| ... | ... | |
| 71 | 87 |
if ( $config ) {
|
| 72 | 88 |
print "graph_title Connected clients\n"; |
| 73 | 89 |
print "graph_vlabel Connected clients\n"; |
| 74 |
print "connected_clients.label connected clients\n"; |
|
| 75 | 90 |
print "graph_category redis\n"; |
| 91 |
print "graph_args -l 0\n"; |
|
| 92 |
print "connected_clients.label connected clients\n"; |
|
| 76 | 93 |
exit 0; |
| 77 | 94 |
} |
| 78 | 95 |
|
| ... | ... | |
| 80 | 97 |
} |
| 81 | 98 |
|
| 82 | 99 |
|
| 100 |
case "keys_per_sec" {
|
|
| 101 |
if ( $config ) {
|
|
| 102 |
print "graph_title Keys Per Second\n"; |
|
| 103 |
print "graph_vlabel per \${graph_period}\n";
|
|
| 104 |
print "graph_category redis\n"; |
|
| 105 |
print "graph_args -l 0\n"; |
|
| 106 |
print "hits.label hits\n"; |
|
| 107 |
print "hits.type COUNTER\n"; |
|
| 108 |
print "misses.label misses\n"; |
|
| 109 |
print "misses.type COUNTER\n"; |
|
| 110 |
print "expired.label expirations\n"; |
|
| 111 |
print "expired.type COUNTER\n"; |
|
| 112 |
print "evictions.label evictions\n"; |
|
| 113 |
print "evictions.type COUNTER\n"; |
|
| 114 |
exit 0; |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
print "hits.value " . $hash->{'keyspace_hits'} . "\n";
|
|
| 118 |
print "misses.value " . $hash->{'keyspace_misses'} . "\n";
|
|
| 119 |
print "expired.value " . $hash->{'expired_keys'} . "\n";
|
|
| 120 |
print "evictions.value " . $hash->{'evicted_keys'} . "\n";
|
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
case "key_ratio" {
|
|
| 124 |
if ( $config ) {
|
|
| 125 |
print "graph_title Key Hit vs Miss Ratio\n"; |
|
| 126 |
print "graph_vlabel per \${graph_period}\n";
|
|
| 127 |
print "graph_category redis\n"; |
|
| 128 |
print "graph_args -u 100 -l 0 -r --base 1000\n"; |
|
| 129 |
print "hitratio.label hit ratio\n"; |
|
| 130 |
print "hitratio.type GAUGE\n"; |
|
| 131 |
print "hitratio.draw AREA\n"; |
|
| 132 |
print "missratio.label miss ratio\n"; |
|
| 133 |
print "missratio.type GAUGE\n"; |
|
| 134 |
print "missratio.draw STACK\n"; |
|
| 135 |
exit 0; |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
my $total = $hash->{'keyspace_hits'} + $hash->{'keyspace_misses'};
|
|
| 139 |
printf("hitratio.value %.2f\n", $hash->{'keyspace_hits'} / $total * 100);
|
|
| 140 |
printf("missratio.value %.2f\n", $hash->{'keyspace_misses'} / $total * 100);
|
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
|
|
| 83 | 144 |
case "per_sec" {
|
| 84 | 145 |
if ( $config ) {
|
| 85 | 146 |
print "graph_title Per second\n"; |
| 86 | 147 |
print "graph_vlabel per \${graph_period}\n";
|
| 87 | 148 |
print "graph_category redis\n"; |
| 149 |
print "graph_args -l 0\n"; |
|
| 88 | 150 |
print "requests.label requests\n"; |
| 89 | 151 |
print "requests.type COUNTER\n"; |
| 90 | 152 |
print "connections.label connections\n"; |
| ... | ... | |
| 101 | 163 |
if ( $config ) {
|
| 102 | 164 |
print "graph_title Used memory\n"; |
| 103 | 165 |
print "graph_vlabel Used memory\n"; |
| 104 |
print "used_memory.label used memory\n"; |
|
| 105 | 166 |
print "graph_category redis\n"; |
| 167 |
print "graph_args -l 0\n"; |
|
| 168 |
print "used_memory.label used memory\n"; |
|
| 169 |
print "used_memory.draw AREA\n"; |
|
| 106 | 170 |
exit 0; |
| 107 | 171 |
} |
| 108 | 172 |
|
| ... | ... | |
| 121 | 185 |
print "graph_title Used keys\n"; |
| 122 | 186 |
print "graph_vlabel Used keys\n"; |
| 123 | 187 |
print "graph_category redis\n"; |
| 188 |
print "graph_args -l 0\n"; |
|
| 124 | 189 |
|
| 125 | 190 |
foreach my $db (keys %{$dbs}) {
|
| 126 | 191 |
printf "%s_keys.label %s keys\n", $db, $db; |
| ... | ... | |
| 137 | 202 |
} |
| 138 | 203 |
} |
| 139 | 204 |
|
| 205 |
sub get_conn {
|
|
| 206 |
my $sock = IO::Socket::INET->new( |
|
| 207 |
PeerAddr => $HOST, |
|
| 208 |
PeerPort => $PORT, |
|
| 209 |
Timeout => 10, |
|
| 210 |
Proto => 'tcp' |
|
| 211 |
); |
|
| 212 |
if ( defined( $PASSWORD ) ) {
|
|
| 213 |
print $sock "AUTH ", $PASSWORD, "\r\n"; |
|
| 214 |
my $result = <$sock> || die "can't read socket: $!"; |
|
| 215 |
} |
|
| 216 |
return $sock; |
|
| 217 |
} |
|
| 218 |
|
|
| 140 | 219 |
# vim: ft=perl ai ts=4 sw=4 et: |
Formats disponibles : Unified diff