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

Add IP/Port

This commit is contained in:
XciD 2014-02-25 10:50:59 +01:00
parent 80dcbf7231
commit fa1298bfde
4 changed files with 177 additions and 98 deletions

0
plugins/rtorrent/rtom_allsessions_mem Normal file → Executable file
View File

55
plugins/rtorrent/rtom_allsessions_peers Normal file → Executable file
View File

@ -28,10 +28,15 @@
#
# Configuration example
#
# [rtom_peers]
# [rtom_allsessions_*]
# user username
# env.src socket
# env.socket /home/usernametorrent/.socket/rpc.socket,/home/usernametorrent/.socket/rpc2.socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category
#
# [rtom_allsessions_*]
# user username
# env.port 5000,5001,5002,5003
# env.category Category
#
#%# family=auto
@ -67,9 +72,10 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) {
use IO::Socket;
my @sockets = split /,/, $ENV{"socket"} || "";
my $mem = 0;
my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || "";
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $tpattern = qr/[0-9A-F]{20}/;
@ -78,7 +84,6 @@ my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.
my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header;
$line = "${hlen}:${header},${line}";
my $tor = 0;
my $tot = 0;
@ -89,16 +94,15 @@ my $ppline = "";
my $out = 0;
my $pla = 0;
if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets)
{
if ( ( defined $src ) && ( $src eq "socket" ) ) {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 );
connect( SOCK, sockaddr_un( $socket ) );
}
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
while ( $line = <SOCK> ) {
if ( $line =~ /$tpattern/ ) {
$tor += 1;
@ -113,10 +117,37 @@ for $socket (@sockets)
$pline = $line;
}
close (SOCK);
$out = $out + $tot - $inc;
$pla = $pla + $tot - $enc;
}
} else {
for $port (@ports)
{
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
while ( $line = <SOCK> ) {
if ( $line =~ /$tpattern/ ) {
$tor += 1;
} elsif ( $line =~ /$pattern/ ) {
$tot += 1;
$enc += $2;
$line = <SOCK>;
$line =~ /$pattern/;
$inc += $2;
}
$ppline = $pline;
$pline = $line;
}
close (SOCK);
$out = $out + $tot - $inc;
$pla = $pla + $tot - $enc;
}
}
print "torrents.value ${tor}\ntotal.value ${tot}\nencrypted.value ${enc}\nplain.value ${pla}\nincoming.value ${inc}\noutgoing.value ${out}\n";
exit;

61
plugins/rtorrent/rtom_allsessions_spdd Normal file → Executable file
View File

@ -40,12 +40,16 @@
#
# Configuration example
#
# [rtom_spdd]
# [rtom_allsessions_*]
# user username
# env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user2/torrent/.socket/rpc2.socket
# env.category Sometext
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category
#
# [rtom_allsessions_*]
# user username
# env.port 5000,5001,5002,5003
# env.category Category
#
#%# family=auto
@ -82,25 +86,26 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) {
}
use IO::Socket;
my @sockets = split /,/, $ENV{"socket"} || "";
my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || "";
my $up = -1;
my $down = -1;
for $socket (@sockets)
{
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>methodName</name><value><string>get_up_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_down_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_upload_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_download_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value></data></array></value></param></params></methodCall>";
my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header;
$line = "${hlen}:${header},${line}";
if ( ( defined $src ) && ( $src eq "socket" ) ) {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 );
connect( SOCK, sockaddr_un( $socket ) );
}
my $up = -1;
my $down = -1;
if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets)
{
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
my $up_tmp = -1;
@ -119,6 +124,34 @@ for $socket (@sockets)
$up = $up + $up_tmp;
$down = $down + $down_tmp;
}
} else {
for $port (@ports)
{
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
my $up_tmp = -1;
my $down_tmp = -1;
while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) {
$up_tmp = $2;
}
}
while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) {
$down_tmp = $2;
}
}
close (SOCK);
$up = $up + $up_tmp;
$down = $down + $down_tmp;
}
}
print "up.value ${up}\ndown.value ${down}\n";
exit;

61
plugins/rtorrent/rtom_allsessions_vol Normal file → Executable file
View File

@ -28,11 +28,16 @@
#
# Configuration example
#
# [rtom_vol]
# [rtom_allsessions_*]
# user username
# env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc2.socket
# env.category Sometext
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category
#
# [rtom_allsessions_*]
# user username
# env.port 5000,5001,5002,5003
# env.category Category
#
#%# family=auto
@ -71,34 +76,28 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) {
use IO::Socket;
my @sockets = split /,/, $ENV{"socket"} || "";
my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || "";
my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/;
my $line;
my $llenmy;
my $header;
my $hlen;
my $num;
foreach ( @views ) {
$num = 0;
for $socket (@sockets){
my $num = 0;
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall</methodName><params><param><value><string>${_}</string></value></param><param><value><string>d.get_hash=</string></value></param></params></methodCall>";
my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header;
if ( ( defined $src ) && ( $src eq "socket" ) ) {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 );
connect( SOCK, sockaddr_un( $socket ) );
}
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall</methodName><params><param><value><string>${_}</string></value></param><param><value><string>d.get_hash=</string></value></param></params></methodCall>";
$llen = length $line;
$header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
$hlen = length $header;
$line = "${hlen}:${header},${line}";
for $socket (@sockets)
{
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) {
$num++;
@ -106,6 +105,22 @@ foreach ( @views ) {
}
close (SOCK);
}
} else {
for $port (@ports)
{
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}";
print SOCK $line;
flush SOCK;
while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) {
$num++;
}
}
close (SOCK);
}
}
print "${_}.value ${num}\n";
}