Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions phpfpm_connections
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ configuration to override the defaults. These are the defaults:
env.url http://127.0.0.1/status
env.ports 80

If your url requires authentication then you can add the following paramters
to the plugin configuration

env.user user001
env.pass pass001
env.realm MyPHP-FPM-Realm

=head1 PARAMETERS:

config (required)
Expand All @@ -40,16 +47,26 @@ Copyright TJ Stein 2010 http://constantshift.com

=cut

#use LWP::ConsoleLogger::Everywhere ();

my $ret = undef;
my $name = '';

if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}

my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status";
if (! eval "require URI;")
{
$ret = "URI 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);
my $USER = exists $ENV{'user'} ? $ENV{'user'} : undef;
my $PASS = exists $ENV{'pass'} ? $ENV{'pass'} : undef;
my $REALM = exists $ENV{'realm'} ? $ENV{'realm'} : undef;

if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
Expand All @@ -64,6 +81,12 @@ if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
my @badports;
foreach my $port (@PORTS) {
my $url = sprintf $URL, $port;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

my $response = $ua->request(HTTP::Request->new('GET',$url));
push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im;
}
Expand All @@ -76,10 +99,14 @@ if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
}
}

if ($0 =~ /phpfpm_connections_(.+)*$/) {
$name = = $1;
}

if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print('graph_title PHP-FPM Accepted Connections
graph_args --base 1024 -l 0
print("graph_title PHP-FPM $name Accepted Connections");
print('graph_args --base 1024 -l 0
graph_vlabel Connections
graph_category PHP
graph_info Plugin created by TJ Stein
Expand All @@ -95,7 +122,14 @@ accepted.min 0
foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);

my $url = sprintf $URL, $port;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /accepted conn:\s+([0-9\.]+)/im) {
print "accepted.value $1\n";
Expand Down
141 changes: 141 additions & 0 deletions phpfpm_connections_
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/perl
# -*- perl -*-

=encoding utf8

=head1 NAME

phpfpm_connections - Munin plugin to monitor the number of accepted connections to 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 php-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

If your url requires authentication then you can add the following paramters
to the plugin configuration

env.user user001
env.pass pass001
env.realm MyPHP-FPM-Realm

=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

#use LWP::ConsoleLogger::Everywhere ();

my $ret = undef;
my $name = '';

if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}

if (! eval "require URI;")
{
$ret = "URI 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);
my $USER = exists $ENV{'user'} ? $ENV{'user'} : undef;
my $PASS = exists $ENV{'pass'} ? $ENV{'pass'} : undef;
my $REALM = exists $ENV{'realm'} ? $ENV{'realm'} : undef;

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;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

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 ($0 =~ /phpfpm_connections_(.+)*$/) {
$name = $1;
}

if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print("graph_title PHP-FPM $name Accepted Connections\n");
print('graph_args --base 1024 -l 0
graph_vlabel Connections
graph_category PHP
graph_info Plugin created by TJ Stein
accepted.label Accepted
accepted.draw AREA
accepted.type DERIVE
accepted.min 0
');

exit 0;
}

foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);

my $url = sprintf $URL, $port;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /accepted conn:\s+([0-9\.]+)/im) {
print "accepted.value $1\n";
} else {
print "accepted.value U\n";
}
}

# vim:syntax=perl
38 changes: 35 additions & 3 deletions phpfpm_status
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ configuration to override the defaults. These are the defaults:
Critical and warning are optional settings and are by default
triggered at 60% and 80% respectively of the total capacity.

If your url requires authentication then you can add the following paramters
to the plugin configuration

env.user user001
env.pass pass001
env.realm MyPHP-FPM-Realm

=head1 PARAMETERS:

config (required)
Expand All @@ -53,8 +60,17 @@ if (! eval "require LWP::UserAgent;")
$ret = "LWP::UserAgent not found";
}

my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status";
if (! eval "require URI;")
{
$ret = "URI 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);
my $USER = exists $ENV{'user'} ? $ENV{'user'} : undef;
my $PASS = exists $ENV{'pass'} ? $ENV{'pass'} : undef;
my $REALM = exists $ENV{'realm'} ? $ENV{'realm'} : undef;


if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
Expand All @@ -69,6 +85,12 @@ if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
my @badports;
foreach my $port (@PORTS) {
my $url = sprintf $URL, $port;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

my $response = $ua->request(HTTP::Request->new('GET',$url));
push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im;
}
Expand All @@ -81,10 +103,14 @@ if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
}
}

if ($0 =~ /phpfpm_connections_(.+)*$/) {
$name = = $1;
}

if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print('graph_title PHP-FPM Status
graph_args --base 1024 -l 0
print("graph_title PHP-FPM $name Status");
print('graph_args --base 1024 -l 0
graph_vlabel Connections
graph_category PHP
graph_order active idle total
Expand All @@ -104,6 +130,12 @@ foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);
my $url = sprintf $URL, $port;

if ( defined $USER and defined $PASS and defined $REALM) {
my $uri = new URI ($url);
$ua->credentials($uri->host.':'.$uri->port,$REALM,$USER,$PASS)
}

my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /idle processes:\s+([0-9\.]+)/im) {
print "idle.value $1\n";
Expand Down
Loading