HomePHP-FPM MonitoringPHP-FPM Monitoring
PHP-FPM Monitoring

PHP-FPM : Nodelizer helps you to monitor following metric about php-fpm installed on your server.

Metrics collected by PHP-FPM Integration
Metric
– Description
Uptime
– The amount of time the server has been running.
Accepted Requests
– The number of request accepted by the pool
Listen Queue
– The number of request in the queue of pending connections. If this number is non-zero, then you better increase number of process FPM can spawn.
Max Listen Queue
– The maximum number of requests in the queue of pending connections since FPM has started
Listen Queue Size
– The size of the socket queue of pending connections
Idle Processes
– The number of idle processes
Active Processes
– The number of active processes
Total Processes
– The number of idle + active processes
Max Active Processes
– The maximum number of active processes since FPM has started
Max Children Reached
– Number of times, the process limit has been reached, when pm tries to start more children. If that value is not zero, then you may need to increase max process limit for your PHP-FPM pool. Like this, you can find other useful information to tweak your pool better way.
Slow Requests
– If this value is non-zero you may have slow php processes. Poorly written mysql queries are generally culprit.
Configuring

Note : rptmonitor parses the PHP-FPM status page output.

  1. Enable status page in PHP-FPM configuration file :

    • Status page is “pool-specific”. Editing the file www.conf will enable status page for default pool www.(You can monitor multiple pools with the agent). Using text editor, find the text “pm.status_path” and you may see a default value for this, but disabled. Enable the option by removing the semicolon at the beginning of line :
    • pm.status_path = /status
    • This will allow the status to be accessed from the URL:
    • http://yourwebservername/status
  2. Configure your Apache / Nginx to catch the URL and redirect through the FPM pool target you want to monitor.

    • For monitoring through Apache:

      Edit your apache configuration file (often at /etc/httpd/conf/httpd.conf – but it can be in many other locations so you may need to search for httpd.conf).

      • We add handler and action which sends all requests of PHP-FPM :

        • Sample for php 5 :

          <LocationMatch “/status”>

          SetHandler php5-fcgi-virt

          Action php5-fcgi-virt /php5-fcgi virtual

          </LocationMatch>

        • Sample for php-fpm 7.0:

          <LocationMatch “/status”>

          Order Allow,Deny

          Allow from 127.0.0.1

          ProxyPass fcgi://127.0.0.1:9000

          </LocationMatch>

      • Apache can be configured to run FastCGI with mod_fastcgi module :

        Edit fastcgi config(mod_fastcgi.conf) :

        LoadModule fastcgi_module modules/mod_fastcgi.so

        <IfModule mod_fastcgi.c>

        DirectoryIndex index.php index.html index.shtml index.cgi

        AddHandler php5-fcgi .php

        Action php5-fcgi /php5-fcgi

        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization

        <LocationMatch “/(ping|status)”

        SetHandler php5-fcgi-virt

        Action php5-fcgi-virt /php5-fcgi virtual

        </LocationMatch>

        </IfModule>

    • For monitoring through Nginx:

      In Nginx config for example.com add a location block like below :

      location ~ ^/(status|ping)$ {

      location ~ ^/(status|ping)$ {

      allow 127.0.0.1;

      allow 1.2.3.4#your-ip;

      deny all;

      include fastcgi_params;

      fastcgi_pass 127.0.0.1:9000;

      }

      Do not forget to replace your IP address. For security reasons, its better to keep your PHP-FPM status page private.

  3. Reload PHP-FPM and Apache / Nginx config for changes to take effect.

  4. Edit the config.cfg file.

    • Uncomment the line containing ‘phpfpm_status_url_1:’ and add the URL.

      phpfpm_status_url_1: http://yourwebservername/status

    • Provide username(phpfpm_usrnm_1) & password(phpfpm_pswd_1) if the status URL is protected. Remove # symbol to uncomment the lines.
    • You can monitor multiple pools with the Agent. Per new pool that you want to monitor, add and configure variables – phpfpm_status_url_n, phpfpm_usrnm_n, phpfpm_pswd_n. ( Replace n = 2, 3, 4….50)
  5. Restart rptmonitor:

    • For (deb/rpm)package supported Linux distros :

      sudo /etc/init.d/rptmonitor restart
    • For other Linux distro, FreeBSD8+, Mac OS X+) :

      sudo python /usr/local/bin/rptmonitor/monitor.py restart