Munin php-fpm status plugin

Been a long long time … but here is something I whipped up. It is a Munin plugin script to gather stats on php-fpm processes. Currently, it only gathers how many Idle and Activate processes are for each pool but can be modified to gather other info outputted from php-fpm’s /status page.

I used this as a basis of my plugin:

http://lumux.co.uk/2012/08/02/php-fpm-status-stats-without-a-webserver/
Here is what the output of /status looks like:

Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Content-Type: text/plain

pool: http://www.nerdifymylife.com
process manager: dynamic
start time: 07/Nov/2013:13:03:53 -0800
start since: 3391
accepted conn: 50
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 1
active processes: 1
total processes: 2
max active processes: 2
max children reached: 0
slow requests: 1

And here is the plugin script:

#!/bin/sh
#
# The following code is released in public domain (where applicable).
# http://creativecommons.org/publicdomain/zero/1.0/

#%# family=auto
#%# capabilities=autoconf suggest

# a list of EXPORTS

export SCRIPT_NAME=/status
export SCRIPT_FILENAME=/status
export REQUEST_METHOD=GET

# location of cgi-fcgi

CGI2FCGI=/usr/bin/cgi-fcgi

#pool=$(echo $0 | awk -F_ '{ print $4 }');

if [ "$1" = "config" ]; then
    # Expose all possibles graphes 

echo "graph_title PHP5-FPM Status";
echo "graph_args --base 1000 -l 0";
echo "graph_vlabel Number of Processes";
echo "graph_category php_fpm_status";

for p in /var/run/apache2/php5-fpm/*.socket;

do

pool=$(echo $p | awk -F/ '{ print $6 }' | perl -pi -e 's/.socket//g' | perl -pi -e 's/./_/g');

echo $pool"_idle.label "$pool "Idle";
echo $pool"_active.label "$pool "Active";

done;

   exit $?

fi

for s in /var/run/apache2/php5-fpm/*.socket;

do

pool=$(echo $s | awk -F/ '{ print $6 }' | perl -pi -e 's/.socket//g' | perl -pi -e 's/./_/g');


${CGI2FCGI} -bind -connect $s | awk -v pool=$pool -F: '

/^active processes:/ {
print pool"_active.value " $2 ;
};

/^idle processes/ {
print pool"_idle.value " $2 ;
};
'
done

Some notes:

1) cgi-fcgi has to be installed.
2) These lines need to be changed to where your sockets are located (if you’re using TCP/IP, then the script needs to be redone):

for p in /var/run/apache2/php5-fpm/*.socket;

3) These lines need to be changed to reflect your socket naming schema:

pool=$(echo $s | awk -F/ ‘{ print $6 }’ | perl -pi -e ‘s/.socket//g’ | perl -pi -e ‘s/./_/g’);

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.