redis: Update munin plugin
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2689|4|2685|3|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/9//ansiblelint">Evolix » ansible-roles » unstable #9</a>
gitea/ansible-roles/pipeline/head This commit looks good

This commit is contained in:
David Prevot 2024-02-22 09:44:38 +01:00
parent b0ba70f06c
commit aea710cb25

View file

@ -1,243 +1,439 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# =head CONFIGURATION
## Copyright (C) 2009 Gleb Voronich <http://stanly.net.ua/>
## Based on Redis module code v0.08 2009/from http://svn.rot13.org/index.cgi/Redis
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License Installation process:
## as published by the Free Software Foundation; version 2 dated June,
## 1991. 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins)
## 2. Symlink it to your configuration directory (e.g. ln -s /usr/share/munin/plugins/redis /etc/munin/plugins/redis)
## This program is distributed in the hope that it will be useful, 3. Edit plugin-conf.d/munin-node with the options to connect to your redis instances (see below for an example)
## but WITHOUT ANY WARRANTY; without even the implied warranty of 4. Restart munin-node service
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details. Example config
## [redis]
## You should have received a copy of the GNU General Public License env.host1 127.0.0.1
## along with this program; if not, write to the Free Software env.port1 6379
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. env.password1 password
## env.title_prefix1 redis-1
## env.host2 /run/redis.sock
## $Log$ env.title_prefix2 redis-2
##
## Based on Redis module code v0.08 2009/from http://svn.rot13.org/index.cgi/Redis Each host should be specified with at least a host or unixsocket variable suffixed with
## a number, the first being 1, the second being 2 etc. They must be in sequence.
## Installation process: Other options are:
## * port - the redis port to connect to
## 1. Download the plugin to your plugins directory (e.g. /usr/share/munin/plugins) * password - the password to use with the AUTH command
## 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 * title_prefix - a prefix to put before the title of the graph, this is strongly recommended for multiple instances
## 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)
## 4. Restart munin-node service Graphs:
## This generates multigraphs for:
## Magic Markers * Connected clients
#%# family=auto * Key Hit vs Miss ratio
#%# capabilities=autoconf suggest * Keys per second, hits/misses/expirations/evictions
* Replication backlog
* Replication lag
* Request per second
* Total number of keys and keys with expires
* Used memory
=head COPYRIGHT
Copyright (C) 2020 Rowan Wookey <https://www.rwky.net/>
Copyright (C) 2009 Gleb Voronich <http://stanly.net.ua/>
=head LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 dated June,
1991.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=head MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
use strict; use strict;
use IO::Socket::INET; use IO::Socket::INET;
use IO::Socket::UNIX; use IO::Socket::UNIX;
use Switch;
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; my %INSTANCES;
my $UNIX_SOCKET = exists $ENV{'unixsocket'} ? $ENV{'unixsocket'} : ''; # path to Redis Unix sock file my $HOST;
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379; my $PORT;
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef; my $PASSWORD;
my $TITLE_PREFIX = exists $ENV{'title_prefix'} ? $ENV{'title_prefix'} . ": " : "";
for (my $i = 1; $ENV{"host$i"}; $i++)
{
$HOST = exists $ENV{"host$i"} ? $ENV{"host$i"} : "127.0.0.1";
$PORT = exists $ENV{"port$i"} ? $ENV{"port$i"} : 6379;
$PASSWORD = exists $ENV{"password$i"} ? $ENV{"password$i"} : undef;
my $TITLE_PREFIX = exists $ENV{"title_prefix$i"} ? $ENV{"title_prefix$i"} . ": " : "";
my $SOCK = &get_conn();
$INSTANCES{"instance$i"} = {
HOST => $HOST,
PORT => $PORT,
PASSWORD => $PASSWORD,
TITLE_PREFIX => $TITLE_PREFIX,
SOCK => $SOCK
};
}
my $sock = &get_conn();
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" ); my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
my $autoconf = ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ); my $autoconf = ( defined $ARGV[0] and $ARGV[0] eq "autoconf" );
if ( $autoconf ) { if ( $autoconf ) {
if ( defined( $sock ) ) { if (!%INSTANCES) {
print "no (no redis instances configured)\n";
exit 0;
}
my $err = '';
for my $INSTANCE (keys %INSTANCES) {
if (! defined( $INSTANCES{$INSTANCE}{'SOCK'} ) ) {
$err = "no (unable to connect to ".$INSTANCES{$INSTANCE}{'HOST'}."\[:". $INSTANCES{$INSTANCE}{'PORT'}."\])\n";
}
}
if ($err) {
print $err;
} else {
print "yes\n"; print "yes\n";
exit 0;
} else {
print "no (unable to connect to $HOST\[:$PORT\])\n";
exit 0;
}
}
my $suggest = ( defined $ARGV[0] and $ARGV[0] eq "suggest" );
if ( $suggest ) {
if ( defined( $sock ) ) {
my @plugins = ('connected_clients', 'key_ratio', 'keys_per_sec', 'per_sec', 'used_keys', 'used_memory');
foreach my $plugin (@plugins) {
print "$plugin\n";
}
exit 0;
} else {
print "no (unable to connect to $HOST\[:$PORT\])\n";
exit 0;
} }
exit 0;
} }
my $hash=&get_info(); my $total = 0;
$0 =~ s/(.+)redis_//g; my $multi_graph_output = '';
my $instance_graph_output = '';
switch ($0) { my $connected_clients = 0;
case "connected_clients" { my $keyspace_hits = 0;
if ( $config ) { my $keyspace_misses = 0;
my $maxclients= get_config("maxclients")->{"maxclients"}; my $expired_keys = 0;
print "graph_title ${TITLE_PREFIX}Connected clients\n"; my $evicted_keys = 0;
print "graph_vlabel Connected clients\n"; my $total_commands_processed = 0;
print "graph_category search\n"; my $total_connections_received = 0;
print "graph_args -l 0\n"; my $repl_backlog_size = 0;
print "connected_clients.line $maxclients:ff0000:Limit\n"; my $used_memory = 0;
print "connected_clients.label connected clients\n"; my $used_memory_rss = 0;
exit 0; my $used_memory_peak = 0;
my $total_keys = 0;
my $total_expires = 0;
foreach my $INSTANCE (keys %INSTANCES) {
my $sock = $INSTANCES{$INSTANCE}{'SOCK'};
my $TITLE_PREFIX = $INSTANCES{$INSTANCE}{'TITLE_PREFIX'};
my $hash = get_info($sock);
my $dbs;
foreach my $key (keys %{$hash}) {
if ( $key =~ /^db\d+$/ && $hash->{$key} =~ /keys=(\d+),expires=(\d+)/ ) {
$total_keys += $1;
$total_expires += $2;
$dbs->{$key} = [ $1, $2 ];
} }
print "connected_clients.value " . $hash->{'connected_clients'} . "\n";
} }
if ( $config ) {
case "keys_per_sec" { my $ret = get_config("maxclients", $sock);
if ( $config ) { # if the CONFIG command is disabled we don't show the max clients
print "graph_title ${TITLE_PREFIX}Keys Per Second\n"; my $maxclients = defined $ret ? $ret->{"maxclients"} : 0;
print "graph_vlabel per \${graph_period}\n"; $instance_graph_output .= "multigraph redis_connected_clients.$INSTANCE\n";
print "graph_category search\n"; $instance_graph_output .= "graph_title ${TITLE_PREFIX}Connected clients\n";
print "graph_args -l 0\n"; $instance_graph_output .= "graph_vlabel Connected clients\n";
print "hits.label hits\n"; $instance_graph_output .= "graph_category db\n";
print "hits.type COUNTER\n"; $instance_graph_output .= "graph_args -l 0\n";
print "misses.label misses\n"; if ($maxclients) {
print "misses.type COUNTER\n"; $instance_graph_output .= "connected_clients.line $maxclients:ff0000:Limit\n";
print "expired.label expirations\n";
print "expired.type COUNTER\n";
print "evictions.label evictions\n";
print "evictions.type COUNTER\n";
exit 0;
} }
$instance_graph_output .= "connected_clients.label connected clients\n";
print "hits.value " . $hash->{'keyspace_hits'} . "\n"; $instance_graph_output .= "multigraph keys_per_sec.$INSTANCE\n";
print "misses.value " . $hash->{'keyspace_misses'} . "\n"; $instance_graph_output .= "graph_title ${TITLE_PREFIX}Keys Per Second\n";
print "expired.value " . $hash->{'expired_keys'} . "\n"; $instance_graph_output .= "graph_vlabel per \${graph_period}\n";
print "evictions.value " . $hash->{'evicted_keys'} . "\n"; $instance_graph_output .= "graph_category db\n";
} $instance_graph_output .= "graph_args -l 0\n";
$instance_graph_output .= "hits.label hits\n";
case "key_ratio" { $instance_graph_output .= "hits.type COUNTER\n";
if ( $config ) { $instance_graph_output .= "misses.label misses\n";
print "graph_title ${TITLE_PREFIX}Key Hit vs Miss Ratio\n"; $instance_graph_output .= "misses.type COUNTER\n";
print "graph_vlabel per \${graph_period}\n"; $instance_graph_output .= "expired.label expirations\n";
print "graph_category search\n"; $instance_graph_output .= "expired.type COUNTER\n";
print "graph_args -u 100 -l 0 -r --base 1000\n"; $instance_graph_output .= "evicted_keys.label evictions\n";
print "hitratio.label hit ratio\n"; $instance_graph_output .= "evicted_keys.type COUNTER\n";
print "hitratio.type GAUGE\n"; $instance_graph_output .= "multigraph redis_key_ratio.$INSTANCE\n";
print "hitratio.draw AREA\n"; $instance_graph_output .= "graph_title ${TITLE_PREFIX}Key Hit vs Miss Ratio\n";
print "missratio.label miss ratio\n"; $instance_graph_output .= "graph_vlabel per \${graph_period}\n";
print "missratio.type GAUGE\n"; $instance_graph_output .= "graph_category db\n";
print "missratio.draw STACK\n"; $instance_graph_output .= "graph_args -u 100 -l 0 -r --base 1000\n";
exit 0; $instance_graph_output .= "hitratio.label hit ratio\n";
} $instance_graph_output .= "hitratio.type GAUGE\n";
$instance_graph_output .= "hitratio.draw AREA\n";
my $total = $hash->{'keyspace_hits'} + $hash->{'keyspace_misses'}; $instance_graph_output .= "missratio.label miss ratio\n";
my $hitratio = 0; $instance_graph_output .= "missratio.type GAUGE\n";
my $missratio = 0; $instance_graph_output .= "missratio.draw STACK\n";
if ($total > 0) { $instance_graph_output .= "multigraph redis_per_sec.$INSTANCE\n";
$hitratio = $hash->{'keyspace_hits'} / $total * 100; $instance_graph_output .= "graph_title ${TITLE_PREFIX}Requests Per second\n";
$missratio = $hash->{'keyspace_misses'} / $total * 100; $instance_graph_output .= "graph_vlabel per \${graph_period}\n";
} $instance_graph_output .= "graph_category db\n";
printf("hitratio.value %.2f\n", $hitratio); $instance_graph_output .= "graph_args -l 0\n";
printf("missratio.value %.2f\n", $missratio); $instance_graph_output .= "requests.label requests\n";
} $instance_graph_output .= "requests.type COUNTER\n";
$instance_graph_output .= "connections.label connections\n";
$instance_graph_output .= "connections.type COUNTER\n";
case "per_sec" { $instance_graph_output .= "multigraph redis_repl_backlog_size.$INSTANCE\n";
if ( $config ) { $instance_graph_output .= "graph_title ${TITLE_PREFIX}replication backlog\n";
print "graph_title ${TITLE_PREFIX}Per second\n"; $instance_graph_output .= "graph_vlabel replication backlog\n";
print "graph_vlabel per \${graph_period}\n"; $instance_graph_output .= "graph_category db\n";
print "graph_category search\n"; $instance_graph_output .= "graph_args -l 0\n";
print "graph_args -l 0\n"; $instance_graph_output .= "repl_backlog_size.label bytes behind master\n";
print "requests.label requests\n"; $instance_graph_output .= "multigraph redis_repl_lag.$INSTANCE\n";
print "requests.type COUNTER\n"; $instance_graph_output .= "graph_title ${TITLE_PREFIX}replication lag\n";
print "connections.label connections\n"; $instance_graph_output .= "graph_vlabel replication lag\n";
print "connections.type COUNTER\n"; $instance_graph_output .= "graph_category db\n";
exit 0; $instance_graph_output .= "graph_args -l 0\n";
} $instance_graph_output .= "repl_backlog_size.label amount behind master\n";
# if the CONFIG command is disabled we don't show maxmemory
print "requests.value ". $hash->{'total_commands_processed'} ."\n"; $ret = get_config("maxmemory", $sock);
print "connections.value ". $hash->{'total_connections_received'} ."\n"; my $maxmemory = defined $ret ? $ret->{"maxmemory"} : 0;
} $instance_graph_output .= "multigraph redis_used_memory.$INSTANCE\n";
$instance_graph_output .= "graph_title ${TITLE_PREFIX}Used memory\n";
$instance_graph_output .= "graph_vlabel Used memory\n";
case "used_memory" { $instance_graph_output .= "graph_category db\n";
if ( $config ) { $instance_graph_output .= "graph_args -l 0 --base 1024\n";
my $maxmemory = get_config("maxmemory")->{"maxmemory"}; if ($maxmemory) {
print "graph_title ${TITLE_PREFIX}Used memory\n"; $instance_graph_output .= "used_memory.line $maxmemory:ff0000:Limit\n";
print "graph_vlabel Used memory\n";
print "graph_category search\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_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" {
my $dbs;
foreach my $key (keys %{$hash}) {
if ( $key =~ /^db\d+$/ && $hash->{$key} =~ /keys=(\d+),expires=(\d+)/ ) {
$dbs->{$key} = [ $1, $2 ];
}
}
if ( $config ) {
print "graph_title ${TITLE_PREFIX}Used keys\n";
print "graph_vlabel Used keys\n";
print "graph_category search\n";
print "graph_args -l 0\n";
foreach my $db (keys %{$dbs}) {
printf "%s_keys.label %s keys\n", $db, $db;
printf "%s_expires.label %s expires\n", $db, $db;
}
exit 0;
} }
$instance_graph_output .= "used_memory.label used memory\n";
$instance_graph_output .= "used_memory_peak.label used memory in peak\n";
$instance_graph_output .= "used_memory_rss.label Resident set size memory usage\n";
$instance_graph_output .= "multigraph redis_used_keys.$INSTANCE\n";
$instance_graph_output .= "graph_title ${TITLE_PREFIX}Used keys\n";
$instance_graph_output .= "graph_vlabel Used keys\n";
$instance_graph_output .= "graph_category db\n";
$instance_graph_output .= "graph_args -l 0\n";
foreach my $db (keys %{$dbs}) { foreach my $db (keys %{$dbs}) {
printf "%s_keys.value %d\n", $db, $dbs->{$db}[0]; $instance_graph_output .= sprintf "%s_keys.label %s keys\n", $db, $db;
printf "%s_expires.value %d\n", $db, $dbs->{$db}[1]; $instance_graph_output .= sprintf "%s_expires.label %s expires\n", $db, $db;
} }
next;
} }
$instance_graph_output .= "multigraph redis_connected_clients.$INSTANCE\n";
$instance_graph_output .= "connected_clients.value " . $hash->{'connected_clients'} . "\n";
$connected_clients += $hash->{'connected_clients'};
$instance_graph_output .= "multigraph keys_per_sec.$INSTANCE\n";
$instance_graph_output .= "hits.value " . $hash->{'keyspace_hits'} . "\n";
$keyspace_hits += $hash->{'keyspace_hits'};
$instance_graph_output .= "misses.value " . $hash->{'keyspace_misses'} . "\n";
$keyspace_misses += $hash->{'keyspace_misses'};
$instance_graph_output .= "expired.value " . $hash->{'expired_keys'} . "\n";
$expired_keys += $hash->{'expired_keys'};
$instance_graph_output .= "evicted_keys.value " . $hash->{'evicted_keys'} . "\n";
$evicted_keys += $hash->{'evicted_keys'};
$instance_graph_output .= "multigraph redis_key_ratio.$INSTANCE\n";
my $total = $hash->{'keyspace_hits'} + $hash->{'keyspace_misses'};
my $hitratio = 0;
my $missratio = 0;
if ($total > 0) {
$hitratio = $hash->{'keyspace_hits'} / $total * 100;
$missratio = $hash->{'keyspace_misses'} / $total * 100;
}
$instance_graph_output .= sprintf("hitratio.value %.2f\n", $hitratio);
$instance_graph_output .= sprintf("missratio.value %.2f\n", $missratio);
$instance_graph_output .= "multigraph redis_per_sec.$INSTANCE\n";
$instance_graph_output .= "requests.value ". $hash->{'total_commands_processed'} ."\n";
$total_commands_processed += $hash->{'total_commands_processed'};
$instance_graph_output .= "connections.value ". $hash->{'total_connections_received'} ."\n";
$total_connections_received += $hash->{'total_connections_received'};
$instance_graph_output .= "multigraph redis_repl_backlog_size.$INSTANCE\n";
$instance_graph_output .= "repl_backlog_size.value " . $hash->{'repl_backlog_size'} . "\n";
$repl_backlog_size += $hash->{'repl_backlog_size'};
$instance_graph_output .= "multigraph redis_repl_lag.$INSTANCE\n";
if (exists $hash->{slave0} && $hash->{slave0} =~ /lag=(\d+)/) {
$repl_backlog_size += $1;
$instance_graph_output .= "repl_backlog_size.value " . $1 . "\n";
} else {
$instance_graph_output .= "repl_backlog_size.value 0\n";
}
$instance_graph_output .= "multigraph redis_used_memory.$INSTANCE\n";
$instance_graph_output .= "used_memory.value ". $hash->{'used_memory'} ."\n";
$used_memory += $hash->{'used_memory'};
$instance_graph_output .= "used_memory_rss.value ". $hash->{'used_memory_rss'} ."\n";
$used_memory_rss += $hash->{'used_memory_rss'};
$instance_graph_output .= "used_memory_peak.value ". $hash->{'used_memory_peak'} ."\n";
$used_memory_peak += $hash->{'used_memory_peak'};
$instance_graph_output .= "multigraph redis_used_keys.$INSTANCE\n";
foreach my $db (keys %{$dbs}) {
$instance_graph_output .= sprintf "%s_keys.value %d\n", $db, $dbs->{$db}[0];
$instance_graph_output .= sprintf "%s_expires.value %d\n", $db, $dbs->{$db}[1];
}
close ($sock);
} }
close ($sock); # multigraph output
if ($config) {
$multi_graph_output .= "multigraph redis_connected_clients\n";
$multi_graph_output .= "graph_title Connected clients\n";
$multi_graph_output .= "graph_vlabel Connected clients\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "connected_clients.label connected clients\n";
$multi_graph_output .= "multigraph keys_per_sec\n";
$multi_graph_output .= "graph_title Keys Per Second\n";
$multi_graph_output .= "graph_vlabel per \${graph_period}\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "hits.label hits\n";
$multi_graph_output .= "hits.type COUNTER\n";
$multi_graph_output .= "misses.label misses\n";
$multi_graph_output .= "misses.type COUNTER\n";
$multi_graph_output .= "expired.label expirations\n";
$multi_graph_output .= "expired.type COUNTER\n";
$multi_graph_output .= "evicted_keys.label evictions\n";
$multi_graph_output .= "evicted_keys.type COUNTER\n";
$multi_graph_output .= "multigraph redis_key_ratio\n";
$multi_graph_output .= "graph_title Key Hit vs Miss Ratio\n";
$multi_graph_output .= "graph_vlabel per \${graph_period}\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -u 100 -l 0 -r --base 1000\n";
$multi_graph_output .= "hitratio.label hit ratio\n";
$multi_graph_output .= "hitratio.type GAUGE\n";
$multi_graph_output .= "hitratio.draw AREA\n";
$multi_graph_output .= "missratio.label miss ratio\n";
$multi_graph_output .= "missratio.type GAUGE\n";
$multi_graph_output .= "missratio.draw STACK\n";
$multi_graph_output .= "multigraph redis_per_sec\n";
$multi_graph_output .= "graph_title Requests Per second\n";
$multi_graph_output .= "graph_vlabel per \${graph_period}\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "requests.label requests\n";
$multi_graph_output .= "requests.type COUNTER\n";
$multi_graph_output .= "connections.label connections\n";
$multi_graph_output .= "connections.type COUNTER\n";
$multi_graph_output .= "multigraph redis_repl_backlog_size\n";
$multi_graph_output .= "graph_title replication backlog\n";
$multi_graph_output .= "graph_vlabel replication backlog\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "repl_backlog_size.label bytes behind master\n";
$multi_graph_output .= "multigraph redis_repl_lag\n";
$multi_graph_output .= "graph_title replication lag\n";
$multi_graph_output .= "graph_vlabel replication lag\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "repl_backlog_size.label amount behind master\n";
$multi_graph_output .= "multigraph redis_used_memory\n";
$multi_graph_output .= "graph_title Used memory\n";
$multi_graph_output .= "graph_vlabel Used memory\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0 --base 1024\n";
$multi_graph_output .= "used_memory.label used memory\n";
$multi_graph_output .= "used_memory_peak.label used memory in peak\n";
$multi_graph_output .= "used_memory_rss.label Resident set size memory usage\n";
$multi_graph_output .= "multigraph redis_used_keys\n";
$multi_graph_output .= "graph_title Used keys\n";
$multi_graph_output .= "graph_vlabel Used keys\n";
$multi_graph_output .= "graph_category db\n";
$multi_graph_output .= "graph_args -l 0\n";
$multi_graph_output .= "total_keys.label Total keys\n";
$multi_graph_output .= "total_expires.label Total expires\n";
} else {
$multi_graph_output .= "multigraph redis_connected_clients\n";
$multi_graph_output .= "connected_clients.value " . $connected_clients . "\n";
$multi_graph_output .= "multigraph keys_per_sec\n";
$multi_graph_output .= "hits.value " . $keyspace_hits . "\n";
$multi_graph_output .= "misses.value " . $keyspace_misses . "\n";
$multi_graph_output .= "expired.value " . $expired_keys . "\n";
$multi_graph_output .= "evicted_keys.value " . $evicted_keys . "\n";
$multi_graph_output .= "multigraph redis_key_ratio\n";
my $total = $keyspace_hits + $keyspace_misses;
my $hitratio = 0;
my $missratio = 0;
if ($total > 0) {
$hitratio = $keyspace_hits / $total * 100;
$missratio = $keyspace_misses / $total * 100;
}
$multi_graph_output .= sprintf("hitratio.value %.2f\n", $hitratio);
$multi_graph_output .= sprintf("missratio.value %.2f\n", $missratio);
$multi_graph_output .= "multigraph redis_per_sec\n";
$multi_graph_output .= "requests.value ". $total_commands_processed ."\n";
$multi_graph_output .= "connections.value ". $total_connections_received ."\n";
$multi_graph_output .= "multigraph redis_repl_backlog_size\n";
$multi_graph_output .= "repl_backlog_size.value " . $repl_backlog_size . "\n";
$multi_graph_output .= "multigraph redis_repl_lag\n";
$multi_graph_output .= "repl_backlog_size.value " . $repl_backlog_size . "\n";
$multi_graph_output .= "multigraph redis_used_memory\n";
$multi_graph_output .= "used_memory.value ". $used_memory ."\n";
$multi_graph_output .= "used_memory_rss.value ". $used_memory_rss ."\n";
$multi_graph_output .= "used_memory_peak.value ". $used_memory_peak ."\n";
$multi_graph_output .= "multigraph redis_used_keys\n";
$multi_graph_output .= "total_keys.value $total_keys\n";
$multi_graph_output .= "total_expires.value $total_expires\n";
}
print $multi_graph_output;
print $instance_graph_output;
sub get_conn { sub get_conn {
my $sock; my $sock;
if( $UNIX_SOCKET && -S $UNIX_SOCKET ){ if(-S $HOST ){
$sock = IO::Socket::UNIX->new( $sock = IO::Socket::UNIX->new(
Type => SOCK_STREAM(), Type => SOCK_STREAM(),
Peer => $UNIX_SOCKET, Peer => $HOST,
); );
}else{ }else{
$sock = IO::Socket::INET->new( $sock = IO::Socket::INET->new(
PeerAddr => $HOST, PeerAddr => $HOST,
PeerPort => $PORT, PeerPort => $PORT,
Timeout => 10, Timeout => 10,
Proto => 'tcp' Proto => 'tcp'
); );
} }
if (! defined($sock)) {
die "can't read socket: $!";
}
if ( defined( $PASSWORD ) ) { if ( defined( $PASSWORD ) ) {
print $sock "AUTH ", $PASSWORD, "\r\n"; print $sock "AUTH ", $PASSWORD, "\r\n";
my $result = <$sock> || die "can't read socket: $!"; my $result = <$sock> || die "can't read socket: $!";
} }
return $sock; return $sock;
} }
sub get_info{ sub get_info{
my $sock = $_[0];
print $sock "INFO\r\n"; print $sock "INFO\r\n";
my $result = <$sock> || die "can't read socket: $!"; my $result = <$sock> || die "can't read socket: $!";
@ -257,13 +453,12 @@ sub get_info{
# This subroutine returns configuration matched to supplied as object # This subroutine returns configuration matched to supplied as object
sub get_config{ sub get_config{
my $sock = $_[1];
print $sock "*3\r\n\$6\r\nCONFIG\r\n\$3\r\nGET\r\n\$".length($_[0])."\r\n".$_[0]."\r\n"; 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 # Response will look like like
# *2\r\n$9\r\nmaxmemory\r\n$10\r\n3221225472\r\n # *2\r\n$9\r\nmaxmemory\r\n$10\r\n3221225472\r\n
my $type = <$sock> || die "can't read socket: $!"; my $type = <$sock> || die "can't read socket: $!";
my $conf; my $conf;
if( substr($type,0,1) ne "*" ) { if( substr($type,0,1) ne "*" ) {
return $conf; return $conf;