mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Merge pull request #435 from rafaltrojniak/master
Redis: Refactoring , information about the limits, more memory statistics
This commit is contained in:
commit
fe49d51245
1 changed files with 61 additions and 15 deletions
|
@ -67,30 +67,19 @@ if ( $suggest ) {
|
|||
}
|
||||
}
|
||||
|
||||
print $sock "INFO\r\n";
|
||||
my $result = <$sock> || die "can't read socket: $!";
|
||||
|
||||
my $rep;
|
||||
read($sock, $rep, substr($result,1)) || die "can't read from socket: $!";
|
||||
|
||||
my $hash;
|
||||
foreach (split(/\r\n/, $rep)) {
|
||||
my ($key,$val) = split(/:/, $_, 2);
|
||||
if (defined($key)) {
|
||||
$hash->{$key} = $val;
|
||||
}
|
||||
}
|
||||
close ($sock);
|
||||
my $hash=&get_info();
|
||||
|
||||
$0 =~ s/(.+)redis_//g;
|
||||
|
||||
switch ($0) {
|
||||
case "connected_clients" {
|
||||
if ( $config ) {
|
||||
my $maxclients= get_config("maxclients")->{"maxclients"};
|
||||
print "graph_title Connected clients\n";
|
||||
print "graph_vlabel Connected clients\n";
|
||||
print "graph_category redis\n";
|
||||
print "graph_args -l 0\n";
|
||||
print "connected_clients.line $maxclients:ff0000:Limit\n";
|
||||
print "connected_clients.label connected clients\n";
|
||||
exit 0;
|
||||
}
|
||||
|
@ -169,16 +158,21 @@ switch ($0) {
|
|||
|
||||
case "used_memory" {
|
||||
if ( $config ) {
|
||||
my $maxmemory = get_config("maxmemory")->{"maxmemory"};
|
||||
print "graph_title Used memory\n";
|
||||
print "graph_vlabel Used memory\n";
|
||||
print "graph_category redis\n";
|
||||
print "graph_args -l 0 --base 1024\n";
|
||||
print "used_memory.line $maxmemory:ff0000:Limit\n";
|
||||
print "used_memory.label used memory\n";
|
||||
print "used_memory.draw AREA\n";
|
||||
print "used_memory_peak.label used memory in peak\n";
|
||||
print "used_memory_rss.label Resident set size memory usage\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
print "used_memory.value ". $hash->{'used_memory'} ."\n";
|
||||
print "used_memory_rss.value ". $hash->{'used_memory_rss'} ."\n";
|
||||
print "used_memory_peak.value ". $hash->{'used_memory_peak'} ."\n";
|
||||
}
|
||||
|
||||
case "used_keys" {
|
||||
|
@ -210,6 +204,8 @@ switch ($0) {
|
|||
}
|
||||
}
|
||||
|
||||
close ($sock);
|
||||
|
||||
sub get_conn {
|
||||
my $sock = IO::Socket::INET->new(
|
||||
PeerAddr => $HOST,
|
||||
|
@ -224,4 +220,54 @@ sub get_conn {
|
|||
return $sock;
|
||||
}
|
||||
|
||||
sub get_info{
|
||||
print $sock "INFO\r\n";
|
||||
my $result = <$sock> || die "can't read socket: $!";
|
||||
|
||||
my $rep;
|
||||
# +2 characters for \r\n at end of the data block
|
||||
read($sock, $rep, substr($result,1)+2) || die "can't read from socket: $!";
|
||||
|
||||
my $hash;
|
||||
foreach (split(/\r\n/, substr($rep, 0, -2))) {
|
||||
my ($key,$val) = split(/:/, $_, 2);
|
||||
if (defined($key)) {
|
||||
$hash->{$key} = $val;
|
||||
}
|
||||
}
|
||||
return $hash;
|
||||
}
|
||||
|
||||
# This subroutine returns configuration matched to supplied as object
|
||||
sub get_config{
|
||||
|
||||
print $sock "*3\r\n\$6\r\nCONFIG\r\n\$3\r\nGET\r\n\$".length($_[0])."\r\n".$_[0]."\r\n";
|
||||
# Response will look like like
|
||||
# *2\r\n$9\r\nmaxmemory\r\n$10\r\n3221225472\r\n
|
||||
|
||||
my $type = <$sock> || die "can't read socket: $!";
|
||||
|
||||
my $conf;
|
||||
if( substr($type,0,1) ne "*" ) {
|
||||
return $conf;
|
||||
}
|
||||
|
||||
my $count=substr($type,1);
|
||||
|
||||
my ( $namesize, $name, $valuesize, $value );
|
||||
while ( $count > 1 ){
|
||||
$count=$count-2;
|
||||
|
||||
$namesize=<$sock>;
|
||||
read($sock, $name, substr($namesize,1)+2) || die "can't read from socket: $!";
|
||||
|
||||
$valuesize=<$sock>;
|
||||
read($sock, $value, substr($valuesize,1)+2) || die "can't read from socket: $!";
|
||||
|
||||
$conf->{substr($name, 0, -2)}=substr($value, 0, -2);
|
||||
}
|
||||
|
||||
return $conf;
|
||||
}
|
||||
|
||||
# vim: ft=perl ai ts=4 sw=4 et:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue