1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

redis plugin: add unixsocket feature

This commit is contained in:
Andrey (suse24) 2015-07-12 23:23:16 +03:00
parent 7f9afa0160
commit 13b6ca382e

View file

@ -35,9 +35,11 @@
use strict; use strict;
use IO::Socket::INET; use IO::Socket::INET;
use IO::Socket::UNIX;
use Switch; use Switch;
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
my $UNIX_SOCKET = exists $ENV{'unixsocket'} ? $ENV{'unixsocket'} : ''; # path to Redis Unix sock file
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379; my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef; my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef;
my $TITLE_PREFIX = exists $ENV{'title_prefix'} ? $ENV{'title_prefix'} . ": " : ""; my $TITLE_PREFIX = exists $ENV{'title_prefix'} ? $ENV{'title_prefix'} . ": " : "";
@ -208,12 +210,26 @@ switch ($0) {
close ($sock); close ($sock);
sub get_conn { sub get_conn {
my $sock = IO::Socket::INET->new(
PeerAddr => $HOST, my $sock;
PeerPort => $PORT,
Timeout => 10, if( $UNIX_SOCKET && -S $UNIX_SOCKET ){
Proto => 'tcp'
); $sock = IO::Socket::UNIX->new(
Type => SOCK_STREAM(),
Peer => $UNIX_SOCKET,
);
}else{
$sock = IO::Socket::INET->new(
PeerAddr => $HOST,
PeerPort => $PORT,
Timeout => 10,
Proto => 'tcp'
);
}
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: $!";