2012-06-14 17:00:05 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# -*- cperl -*-
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2013-05-06 12:09:06 +02:00
|
|
|
php_fpm_process - Munin plugin to show number of number of use processes on php-fpm.
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
Inspirated by php5-fpm_status plugin by Daniel Caillibaud
|
|
|
|
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
Any php-fpm host
|
|
|
|
You will need the perl fastcgi::client on your host
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
You have to put this in your plugin.conf.d folder
|
2012-06-14 17:00:05 +02:00
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
# If your php process is listening on TCP
|
2012-06-14 17:00:05 +02:00
|
|
|
[php_fpm_process]
|
|
|
|
env.serveraddr 127.0.0.1
|
|
|
|
env.port 9000
|
2016-01-08 17:28:29 +01:00
|
|
|
env.path /status
|
2012-06-14 17:00:05 +02:00
|
|
|
|
2014-02-20 06:31:39 +01:00
|
|
|
# If your php process is listening on Unix Socket
|
|
|
|
[php_fpm_process]
|
|
|
|
env.sock /var/run/php5-fpm.sock
|
2016-01-08 17:28:29 +01:00
|
|
|
env.path /status
|
2014-02-20 06:31:39 +01:00
|
|
|
|
2012-06-14 17:00:05 +02:00
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=head1 VERSION
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
v1.0
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
Minitux
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GNU General Public License, version 3
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
use File::Basename;
|
2012-06-14 17:00:05 +02:00
|
|
|
use FCGI::Client;
|
|
|
|
|
|
|
|
my $ish = 1;
|
|
|
|
my $header = "";
|
|
|
|
my $body = "";
|
|
|
|
my $IDLE = 0;
|
|
|
|
my $ACTIVE = 0;
|
|
|
|
my $TOTAL = 0;
|
2016-01-08 17:28:29 +01:00
|
|
|
my $SLOW_REQUESTS = 0;
|
|
|
|
my $PLUGIN_NAME = basename($0);
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
|
|
|
my $PORT = $ENV{'port'} || "9000";
|
|
|
|
my $PATH = $ENV{'path'} || "/status";
|
2014-02-20 06:31:39 +01:00
|
|
|
my $UNIX_SOCK = $ENV{'sock'};
|
|
|
|
|
|
|
|
my $sock;
|
|
|
|
|
|
|
|
if ($UNIX_SOCK) {
|
|
|
|
use IO::Socket::UNIX;
|
|
|
|
$sock = IO::Socket::UNIX->new(
|
|
|
|
Peer => $UNIX_SOCK,
|
|
|
|
);
|
2016-01-08 17:28:29 +01:00
|
|
|
if (!$sock) {
|
2014-02-20 06:31:39 +01:00
|
|
|
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,
|
|
|
|
);
|
2016-01-08 17:28:29 +01:00
|
|
|
if (!$sock) {
|
2014-02-20 06:31:39 +01:00
|
|
|
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
|
|
|
|
exit 2;
|
|
|
|
}
|
2012-06-14 17:00:05 +02:00
|
|
|
}
|
|
|
|
|
2014-02-20 06:31:39 +01:00
|
|
|
my $client = FCGI::Client::Connection->new( sock => $sock );
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
my ( $stdout, $stderr, $appstatus ) = $client->request(
|
2014-02-20 06:31:39 +01:00
|
|
|
+{
|
|
|
|
REQUEST_METHOD => 'GET',
|
|
|
|
SCRIPT_FILENAME => '',
|
|
|
|
QUERY_STRING => '',
|
|
|
|
SCRIPT_NAME => $PATH,
|
|
|
|
},
|
|
|
|
''
|
|
|
|
);
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
$stdout =~ s/\r//g;
|
|
|
|
|
|
|
|
while($stdout =~ /([^\n]*)\n?/g) {
|
2014-02-20 06:31:39 +01:00
|
|
|
if(!$1) {
|
|
|
|
$ish = 0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($ish == 1) {
|
|
|
|
$header .= $1."\n";
|
|
|
|
} else {
|
|
|
|
$body .= $1."\n";
|
|
|
|
}
|
2013-05-06 12:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
|
|
|
|
{
|
2016-01-08 17:28:29 +01:00
|
|
|
|
2013-05-06 12:09:06 +02:00
|
|
|
if($body =~ m/pool:\s+(.*?)\n/) {
|
|
|
|
$pool = $1;
|
|
|
|
}
|
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
print <<"EOF";
|
|
|
|
multigraph ${PLUGIN_NAME}_process
|
|
|
|
graph_title php5-fpm processes for $pool
|
|
|
|
graph_args --base 1000 -l 0
|
|
|
|
graph_vlabel Processes
|
|
|
|
graph_scale yes
|
|
|
|
graph_category php-fpm
|
|
|
|
graph_info This graph shows the php5-fpm process manager status from pool: $pool
|
|
|
|
active.label Active processes
|
|
|
|
active.type GAUGE
|
|
|
|
active.draw AREA
|
|
|
|
active.info The number of active processes
|
|
|
|
idle.label Idle processes
|
|
|
|
idle.type GAUGE
|
|
|
|
idle.draw STACK
|
|
|
|
idle.info The number of idle processes
|
|
|
|
total.label Total processes
|
|
|
|
total.type GAUGE
|
|
|
|
total.draw LINE2
|
|
|
|
total.info The number of idle + active processes
|
|
|
|
|
|
|
|
multigraph ${PLUGIN_NAME}_slowrequests
|
|
|
|
graph_title php5-fpm slow requests $pool
|
|
|
|
graph_args --base 1000 -l 0
|
|
|
|
graph_vlabel Slow requests
|
|
|
|
graph_scale yes
|
|
|
|
graph_category php-fpm
|
|
|
|
graph_info This graph shows the php5-fpm slow request from pool: $pool
|
|
|
|
slow_requests.label Slow requests
|
|
|
|
slow_requests.type DERIVE
|
|
|
|
slow_requests.draw LINE2
|
|
|
|
slow_requests.min 0
|
|
|
|
slow_requests.info evolution of slow requests
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2013-05-06 12:09:06 +02:00
|
|
|
exit 0
|
2016-01-08 17:28:29 +01:00
|
|
|
}
|
2014-02-20 06:31:39 +01:00
|
|
|
|
2016-01-08 17:28:29 +01:00
|
|
|
# print $body;
|
|
|
|
|
|
|
|
print "multigraph ${PLUGIN_NAME}_process\n";
|
2012-06-14 17:00:05 +02:00
|
|
|
|
|
|
|
if($body =~ m/idle processes: (.*?)\n/) {
|
|
|
|
$IDLE = $1;
|
2014-02-20 06:31:39 +01:00
|
|
|
print "idle.value ".$IDLE."\n";
|
2012-06-14 17:00:05 +02:00
|
|
|
}
|
|
|
|
if($body =~ m/active processes: (.*?)\n/) {
|
|
|
|
$ACTIVE = $1;
|
2014-02-20 06:31:39 +01:00
|
|
|
print "active.value ".$ACTIVE."\n";
|
2012-06-14 17:00:05 +02:00
|
|
|
}
|
|
|
|
if($body =~ m/total processes: (.*?)\n/) {
|
|
|
|
$TOTAL = $1;
|
2014-02-20 06:31:39 +01:00
|
|
|
print "total.value ".$TOTAL."\n";
|
2012-06-14 17:00:05 +02:00
|
|
|
}
|
2016-01-08 17:28:29 +01:00
|
|
|
|
|
|
|
if($body =~ m/slow requests: (.*?)\n/) {
|
|
|
|
$SLOW_REQUESTS = $1;
|
|
|
|
print "\n";
|
|
|
|
print "multigraph ${PLUGIN_NAME}_slowrequests\n";
|
|
|
|
print "slow_requests.value ".$SLOW_REQUESTS."\n";
|
|
|
|
}
|