Monitor PHP-FPM with Nixstats

Metrics

The following metrics are submitted to Nixstats.

  • Accepted connections (per second, total)
  • Active processes
  • Total processes
  • Idle processes
  • Max active processes
  • Listen queue
  • Listen queue length
  • Max listen queue
  • Max children reached
  • Start time
  • Start since
  • Pool
  • Process manager
  • Slow requests

Dependencies

  • urllib2
  • json

PHP-FPM status page

To enable the PHP-FPM status page add the following code to your PHP-FPM pool configuration file.

pm.status_path = /status_phpfpm

Now make the following changes to your NGiNX configuration file.

server {
    listen 127.0.0.1:8080;
    server_name localhost;
    location /status_phpfpm {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        allow 127.0.0.1;
        deny all;
    }
} 

You can test if the status page is working by running
wget -qO- http://127.0.0.1:8080/status_phpfpm?json

Configure the plugin

To enable the plugin edit the nixstats configuration file. This file is usually located at /etc/nixstats.ini.

Add the following settings to the end of the file.

[phpfpm] 
enabled = yes
status_page_url = http://127.0.0.1:8080/status_phpfpm?json

Test to see if the plugin is working by running nixstatsagent --test phpfpm. It should show the following metrics:

phpfpm:
{
    "accepted_conn": 3015,
    "accepted_conn_per_second": 0.0,
    "active_processes": 1,
    "idle_processes": 0,
    "listen_queue": 0,
    "listen_queue_len": 128,
    "max_active_processes": 1,
    "max_children_reached": 0,
    "max_listen_queue": 1,
    "pool": "www",
    "process_manager": "ondemand",
    "slow_requests": 0,
    "start_since": 294686,
    "start_time": 1492504250,
    "total_processes": 1
}

Now you can restart the agent service nixstatsagent restart to start monitoring PHP-FPM.