mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Add unix socket support, change some indent / format.
This commit is contained in:
parent
5e2aaa3a67
commit
926c0ee4cd
1 changed files with 53 additions and 32 deletions
|
@ -17,11 +17,17 @@ You will need the perl fastcgi::client on your host
|
||||||
|
|
||||||
You have to put this in your plugin.conf.d folder
|
You have to put this in your plugin.conf.d folder
|
||||||
|
|
||||||
|
# If your php process is listening on TCP
|
||||||
[php_fpm_process]
|
[php_fpm_process]
|
||||||
env.serveraddr 127.0.0.1
|
env.serveraddr 127.0.0.1
|
||||||
env.port 9000
|
env.port 9000
|
||||||
env.path /status
|
env.path /status
|
||||||
|
|
||||||
|
# If your php process is listening on Unix Socket
|
||||||
|
[php_fpm_process]
|
||||||
|
env.sock /var/run/php5-fpm.sock
|
||||||
|
env.path /status
|
||||||
|
|
||||||
=head1 MAGIC MARKERS
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
#%# family=auto
|
#%# family=auto
|
||||||
|
@ -41,8 +47,6 @@ GNU General Public License, version 3
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
||||||
use IO::Socket::INET;
|
|
||||||
use FCGI::Client;
|
use FCGI::Client;
|
||||||
|
|
||||||
my $ish = 1;
|
my $ish = 1;
|
||||||
|
@ -55,40 +59,55 @@ my $TOTAL = 0;
|
||||||
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
||||||
my $PORT = $ENV{'port'} || "9000";
|
my $PORT = $ENV{'port'} || "9000";
|
||||||
my $PATH = $ENV{'path'} || "/status";
|
my $PATH = $ENV{'path'} || "/status";
|
||||||
|
my $UNIX_SOCK = $ENV{'sock'};
|
||||||
|
|
||||||
my $sock = IO::Socket::INET->new(
|
my $sock;
|
||||||
PeerAddr => $SERVERADDR,
|
|
||||||
PeerPort => $PORT,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$sock) {
|
if ($UNIX_SOCK) {
|
||||||
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
|
use IO::Socket::UNIX;
|
||||||
exit 2;
|
$sock = IO::Socket::UNIX->new(
|
||||||
|
Peer => $UNIX_SOCK,
|
||||||
|
);
|
||||||
|
if (!$sock) {
|
||||||
|
print "Server maybe down, unabled to connect to $UNIX_SOCK";
|
||||||
|
exit 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
use IO::Socket::INET;
|
||||||
|
$sock = IO::Socket::INET->new(
|
||||||
|
PeerAddr => $SERVERADDR,
|
||||||
|
PeerPort => $PORT,
|
||||||
|
);
|
||||||
|
if (!$sock) {
|
||||||
|
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
|
||||||
|
exit 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $client = FCGI::Client::Connection->new( sock => $sock );
|
my $client = FCGI::Client::Connection->new( sock => $sock );
|
||||||
my ( $stdout, $stderr, $appstatus ) = $client->request(
|
|
||||||
+{
|
my ( $stdout, $stderr, $appstatus ) = $client->request(
|
||||||
REQUEST_METHOD => 'GET',
|
+{
|
||||||
SCRIPT_FILENAME => '',
|
REQUEST_METHOD => 'GET',
|
||||||
QUERY_STRING => '',
|
SCRIPT_FILENAME => '',
|
||||||
SCRIPT_NAME => $PATH,
|
QUERY_STRING => '',
|
||||||
},
|
SCRIPT_NAME => $PATH,
|
||||||
''
|
},
|
||||||
);
|
''
|
||||||
|
);
|
||||||
|
|
||||||
$stdout =~ s/\r//g;
|
$stdout =~ s/\r//g;
|
||||||
|
|
||||||
while($stdout =~ /([^\n]*)\n?/g) {
|
while($stdout =~ /([^\n]*)\n?/g) {
|
||||||
if(!$1) {
|
if(!$1) {
|
||||||
$ish = 0;
|
$ish = 0;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if($ish == 1) {
|
if($ish == 1) {
|
||||||
$header .= $1."\n";
|
$header .= $1."\n";
|
||||||
} else {
|
} else {
|
||||||
$body .= $1."\n";
|
$body .= $1."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
|
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
|
||||||
|
@ -119,15 +138,17 @@ if ( defined $ARGV[0] and $ARGV[0] eq "config" )
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print $body;
|
||||||
|
|
||||||
if($body =~ m/idle processes: (.*?)\n/) {
|
if($body =~ m/idle processes: (.*?)\n/) {
|
||||||
$IDLE = $1;
|
$IDLE = $1;
|
||||||
print "idle.value ".$IDLE."\n";
|
print "idle.value ".$IDLE."\n";
|
||||||
}
|
}
|
||||||
if($body =~ m/active processes: (.*?)\n/) {
|
if($body =~ m/active processes: (.*?)\n/) {
|
||||||
$ACTIVE = $1;
|
$ACTIVE = $1;
|
||||||
print "active.value ".$ACTIVE."\n";
|
print "active.value ".$ACTIVE."\n";
|
||||||
}
|
}
|
||||||
if($body =~ m/total processes: (.*?)\n/) {
|
if($body =~ m/total processes: (.*?)\n/) {
|
||||||
$TOTAL = $1;
|
$TOTAL = $1;
|
||||||
print "total.value ".$TOTAL."\n";
|
print "total.value ".$TOTAL."\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue