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

added slow requests for php fpm (going multigraph)

This commit is contained in:
Raphaël Droz 2016-01-08 13:28:29 -03:00
parent 5eaf9dd2d4
commit f8bf3961da

View File

@ -10,23 +10,23 @@ Inspirated by php5-fpm_status plugin by Daniel Caillibaud
=head1 APPLICABLE SYSTEMS =head1 APPLICABLE SYSTEMS
Any php-fpm host Any php-fpm host
You will need the perl fastcgi::client on your host You will need the perl fastcgi::client on your host
=head1 CONFIGURATION =head1 CONFIGURATION
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 # 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 # If your php process is listening on Unix Socket
[php_fpm_process] [php_fpm_process]
env.sock /var/run/php5-fpm.sock env.sock /var/run/php5-fpm.sock
env.path /status env.path /status
=head1 MAGIC MARKERS =head1 MAGIC MARKERS
@ -35,11 +35,11 @@ You have to put this in your plugin.conf.d folder
=head1 VERSION =head1 VERSION
v1.0 v1.0
=head1 AUTHOR =head1 AUTHOR
Minitux Minitux
=head1 LICENSE =head1 LICENSE
@ -47,6 +47,7 @@ GNU General Public License, version 3
=cut =cut
use File::Basename;
use FCGI::Client; use FCGI::Client;
my $ish = 1; my $ish = 1;
@ -55,6 +56,8 @@ my $body = "";
my $IDLE = 0; my $IDLE = 0;
my $ACTIVE = 0; my $ACTIVE = 0;
my $TOTAL = 0; my $TOTAL = 0;
my $SLOW_REQUESTS = 0;
my $PLUGIN_NAME = basename($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";
@ -68,7 +71,7 @@ if ($UNIX_SOCK) {
$sock = IO::Socket::UNIX->new( $sock = IO::Socket::UNIX->new(
Peer => $UNIX_SOCK, Peer => $UNIX_SOCK,
); );
if (!$sock) { if (!$sock) {
print "Server maybe down, unabled to connect to $UNIX_SOCK"; print "Server maybe down, unabled to connect to $UNIX_SOCK";
exit 2; exit 2;
} }
@ -78,7 +81,7 @@ if ($UNIX_SOCK) {
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;
} }
@ -86,7 +89,7 @@ if ($UNIX_SOCK) {
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',
SCRIPT_FILENAME => '', SCRIPT_FILENAME => '',
@ -112,33 +115,53 @@ while($stdout =~ /([^\n]*)\n?/g) {
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{ {
if($body =~ m/pool:\s+(.*?)\n/) { if($body =~ m/pool:\s+(.*?)\n/) {
$pool = $1; $pool = $1;
} }
print "graph_title php5-fpm status $pool\n"; print <<"EOF";
print "graph_args --base 1000 -l 0\n"; multigraph ${PLUGIN_NAME}_process
print "graph_vlabel Processes\n"; graph_title php5-fpm processes for $pool
print "graph_scale yes\n"; graph_args --base 1000 -l 0
print "graph_category php-fpm\n"; graph_vlabel Processes
print "graph_info This graph shows the php5-fpm process manager status from pool: $pool\n"; graph_scale yes
print "active.label Active processes\n"; graph_category php-fpm
print "active.type GAUGE\n"; graph_info This graph shows the php5-fpm process manager status from pool: $pool
print "active.draw AREA\n"; active.label Active processes
print "active.info The number of active processes\n"; active.type GAUGE
print "idle.label Idle processes\n"; active.draw AREA
print "idle.type GAUGE\n"; active.info The number of active processes
print "idle.draw STACK\n"; idle.label Idle processes
print "idle.info The number of idle processes\n"; idle.type GAUGE
print "total.label Total processes\n"; idle.draw STACK
print "total.type GAUGE\n"; idle.info The number of idle processes
print "total.draw LINE2\n"; total.label Total processes
print "total.info The number of idle + active processes\n"; total.type GAUGE
exit 0 total.draw LINE2
} total.info The number of idle + active processes
print $body; 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
exit 0
}
# print $body;
print "multigraph ${PLUGIN_NAME}_process\n";
if($body =~ m/idle processes: (.*?)\n/) { if($body =~ m/idle processes: (.*?)\n/) {
$IDLE = $1; $IDLE = $1;
@ -152,3 +175,10 @@ if($body =~ m/total processes: (.*?)\n/) {
$TOTAL = $1; $TOTAL = $1;
print "total.value ".$TOTAL."\n"; print "total.value ".$TOTAL."\n";
} }
if($body =~ m/slow requests: (.*?)\n/) {
$SLOW_REQUESTS = $1;
print "\n";
print "multigraph ${PLUGIN_NAME}_slowrequests\n";
print "slow_requests.value ".$SLOW_REQUESTS."\n";
}