Projet

Général

Profil

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

root / plugins / other / redis @ b54782b7

Historique | Voir | Annoter | Télécharger (3,15 ko)

1
#!/usr/bin/perl -w
2

    
3
#
4
## Copyright (C) 2009 Gleb Voronich <http://stanly.net.ua/>
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 Redis module code v0.08 2009/from http://svn.rot13.org/index.cgi/Redis
24
##
25
## Installation process:
26
##
27
## 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins)
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
## 3. Edit plugin-conf.d/munin-node if it is needed (env.host and  env.port variables are accepted)
30
## 4. Restart munin-node service
31

    
32
use strict;
33
use IO::Socket::INET;
34
use Switch;
35

    
36
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
37
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
38

    
39
my $server = "$HOST:$PORT";
40
my $sock = IO::Socket::INET->new(
41
	PeerAddr => $server,
42
	Proto => 'tcp'
43
);
44

    
45
print $sock "INFO\r\n";
46
my $result = <$sock> || die "can't read socket: $!";
47

    
48
my $rep;
49
read($sock, $rep, substr($result,1)) || die "can't read from socket: $!";
50

    
51
my $hash;
52
foreach (split(/\r\n/, $rep)) {
53
  my ($key,$val) = split(/:/, $_, 2);
54
  $hash->{$key} = $val;
55
}
56
close ($sock);
57

    
58

    
59
$0 =~ s/(.+)redis_//g;
60

    
61
switch ($0) {
62
    case "connected_clients" {
63
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
64
            print "graph_title Connected clients\n";
65
            print "graph_vlabel Connected clients\n";
66
            print "connected_clients.label connected clients\n";
67
            print "graph_category redis\n";
68
            exit 0;
69
	}
70
	print "connected_clients.value " . $hash->{'connected_clients'} . "\n";
71
    }
72

    
73

    
74
    case "per_sec" {
75
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
76
            print "graph_title Per second\n";
77
            print "graph_vlabel per \${graph_period}\n";
78
            print "graph_category redis\n";
79
            print "requests.label requests\n";
80
            print "requests.type COUNTER\n";
81
            print "connections.label connections\n";
82
            print "connections.type COUNTER\n";
83
            exit 0;
84
	}
85
	print "requests.value ". $hash->{'total_commands_processed'} ."\n";
86
	print "connections.value ". $hash->{'total_connections_received'} ."\n";
87
    }
88

    
89

    
90
    case "used_memory" {
91
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
92
            print "graph_title Used memory\n";
93
            print "graph_vlabel Used memory\n";
94
            print "used_memory.label used memory\n";
95
            print "graph_category redis\n";
96
            exit 0;
97
	}
98
	print "used_memory.value ". $hash->{'used_memory'}  ."\n";
99
    }
100
}