2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/redis/redis-speed

65 lines
1.9 KiB
Text
Raw Normal View History

2010-07-29 17:24:46 +02:00
#!/usr/bin/perl -w
#
## Copyright (C) 2010 KARASZI Istvan <http://raszi.hu/>
##
## 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.
##
#
use strict;
use Redis;
use Time::HiRes qw( gettimeofday tv_interval );
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef ;
2010-07-29 17:24:46 +02:00
my $server = "$HOST:$PORT";
my $r = Redis->new( server => $server, password => $PASSWORD );
2010-07-29 17:24:46 +02:00
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
sub get_time {
my ($times, $func) = @_;
my $start = [ gettimeofday ];
for (my $i = 0; $i < $times; $i++) {
$func->();
}
return sprintf("%f", tv_interval($start) / $times);
}
if ( $config ) {
print "graph_title Response time\n";
print "graph_vlabel Response time\n";
print "ping.label PING time\n";
print "get.label GET time\n";
print "set.label SET time\n";
print "graph_category redis\n";
exit 0;
}
my $key = "test-key";
2012-08-21 16:44:06 +02:00
my $times = 20;
2010-07-29 17:24:46 +02:00
print "ping.value " . &get_time( $times, sub { $r->ping(); }) . "\n";
2012-08-21 16:44:06 +02:00
print "set.value " . &get_time( $times, sub { $r->set($key => 'SET ' . $key . ' 1'); }) . "\n";
2010-07-29 17:24:46 +02:00
print "get.value " . &get_time( $times, sub { $r->get($key); }) . "\n";
# vim: ft=perl ai ts=4 sw=4 et: