Recently, I have to configure my account at ServerDensity to monitor PHP-FPM activities on one of my servers. It came out that there’s not so many tutorials on how to setup PHP-FPM status page. This is the key to the problem of monitoring PHP-FPM via ServerDensity plugin. From what I’ve experienced, I hope I could provide a good reference for those who are looking for one.

So, first things first!

STEP 1: Enable PHP-FPM status page

Find and enable status page in PHP-FPM configuration file. My server is Ubuntu so the configuration files for PHP-FPM are located at /etc/php5/fpm/. As PHP-FPM processes are divided by pool, so status page is also “pool-specific” and should be at pool config files at /etc/php5/fpm/pool.d/.

The default pool for PHP-FPM is www so I am going to edit the file www.conf to enable status page for this pool.

Use a text editor, find the text “pm.status_path” and you may see there’s already a default value for this, but disabled. You can enable the option by simply removing the semicolon at the beginning of the line, having:

pm.status_path = /status

This means you can access to a page, which will show you information about currently running PHP-FPM processes, at the address http://yourwebservername/status.

Save the file and the first step is finished!

STEP 2: Configuring nginx to actually have access to status page

Again, I am using a Ubuntu server so nginx configuration files in my case are stored at /etc/nginx/.

Ubuntu manages configuration of sites hosted by means of “VirtualHost”, placed in /etc/nginx/sites-enabled/. Howerver, for the purpose of management, we only need the PHP-FPM status page to be accessible from localhost (and the ServerDensity plugin will do so), so it’s reasonable to add a location block to a global configuration file at /etc/nginx/conf.d/default.conf.

location /status {
	fastcgi_pass 127.0.0.1:9000;
	fastcgi_index index.php;
	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
	allow 127.0.0.1;
	deny all;
}

Save the file, reload nginx server with the command /etc/init.d/nginx reload and you will be able to access PHP-FPM status page at http://127.0.0.1/status

You could test using the command:

curl http://127.0.0.1/status

and if you see something like this, you are all set!

accepted conn:   123
pool:             www
process manager:  dynamic
idle processes:   9
active processes: 1
total processes:  10

Now you can just install the PHP-FPM monitoring plugin by following the on-screen instruction. Wait for a few minutes before you can visually track how the PHP-FPM manages PHP requests to your server :)


Tips: If you don’t see the visual graph of data for PHP-FPM after about 10 minutes, try to add the status page url to sd-agent config file (mine at /etc/sd-agent/config.cfg). You need a line similar to this:

fpm_status_url = http://127.0.0.1/status

Restart the sd-agent with the command below (if you are using Debian/Ubuntu) and you will be fine for sure!

/etc/init.d/sd-agent restart