Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
138 lines (104 sloc) 2.95 KB
#!/usr/bin/perl
# -*- perl -*-
=encoding utf8
=head1 NAME
phpfpm_status - Munin plugin to monitor the staus of PHP-FPM.
=head1 CONFIGURATION
For this plugin, you will need to enable the status feature
included in versions 5.3.2+ of PHP-FPM. The directive can be
found in the php5-fpm.conf file:
pm.status_path = /status
You might need to specify connection parameters in the plugin
configuration to override the defaults. These are the defaults:
[phpfpm_*]
env.url http://127.0.0.1/status
env.ports 80
env.warning 0.6
env.critical 0.8
Critical and warning are optional settings and are by default
triggered at 60% and 80% respectively of the total capacity.
=head1 PARAMETERS:
config (required)
autoconf (optional - used by munin-config)
=over
=head1 LICENSE
Copyright TJ Stein 2010 http://constantshift.com
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status";
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
if ($ret)
{
print "no ($ret)\n";
exit 1;
}
my $ua = LWP::UserAgent->new(timeout => 30);
my @badports;
foreach my $port (@PORTS) {
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im;
}
if (@badports) {
print "no (phpfpm-status)\n";
exit 1;
} else {
print "yes\n";
exit 0;
}
}
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print('graph_title PHP-FPM Status
graph_args --base 1024 -l 0
graph_vlabel Connections
graph_category PHP
graph_order active idle total
graph_info Plugin created by TJ Stein
active.label Active
active.draw AREA
idle.label Idle
idle.draw STACK
total.label Total
total.draw LINE1
');
exit 0;
}
foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /idle processes:\s+([0-9\.]+)/im) {
print "idle.value $1\n";
} else {
print "idle.value U\n";
}
if ($response->content =~ /active processes:\s+([0-9\.]+)/im) {
print "active.value $1\n";
} else {
print "active.value U\n";
}
if ($response->content =~ /total processes:\s+([0-9\.]+)/im) {
print "total.value $1\n";
} else {
print "total.value U\n";
}
my $total = $1;
my $warning_threshold = exists $ENV{warning} ? $ENV{warning} : '0.60';
my $critical_threshold = exists $ENV{critical} ? $ENV{critical} : '0.80';
my $warning_level = int($total*$warning_threshold);
my $critical_level = int($total*$critical_threshold);
print ("active.warning $warning_level\n");
print ("active.critical $critical_level\n");
}
# vim:syntax=perl