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

Merge pull request #457 from zbal/php-fpm-status

Add unix socket support, change some indent / format.
This commit is contained in:
Steve Schnepp 2014-02-21 13:48:24 +01:00
commit 8a91cd30f7

View file

@ -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,18 +59,33 @@ 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;
if ($UNIX_SOCK) {
use IO::Socket::UNIX;
$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, PeerAddr => $SERVERADDR,
PeerPort => $PORT, PeerPort => $PORT,
); );
if (!$sock) { if (!$sock) {
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT"; print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
exit 2; 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', REQUEST_METHOD => 'GET',
@ -119,6 +138,8 @@ 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";