Using PHP Exporter

How to monitor PHP-FPM stuff in Prometheus


A while ago, we had a client in my current job which had very little monitoring of their solutions. We had problems with the boxes where it would freeze and not really give us an answer as to what happened. Now the fix for that was actually quite trivial (and had nothing to do with what we thought it would be), but it’s a good reminder that we should always have a nice monitoring solution to have a view of what services are running and what aren’t.


I’m a big fan of Prometheus and Grafana, having used them in my last few gigs, and the fact that there are exporters everywhere for various different things. For this client/service, it was monitoring something that I haven’t touched in years… PHP.


PHP is quite abundant is open source resources, but I completely struggled to find any information regarding PHP exporter and how to get it up and running etc, so that’s why I’m writing this blog. So let’s get started. For the purposes of this, I’m assuming you have Prometheus/Alertmanager already up and running.


The exporter I’m talking about is this one.
https://github.com/hipages/php-fpm_exporter

  1. To get started, SSH onto your server/container that you are monitoring the service.

  2. Create a new user for the exporter:
    sudo useradd --no-create-home php-fpm_exporter

  3. Get the PHP-FPM exporter, and then move it to your local/bin folder:

    1
    2
    3
    
       wget https://github.com/hipages/php-fpm_exporter/releases/download/v2.0.2/php-fpm_exporter_2.0.2_linux_amd64
       mv php-fpm_exporter_2.0.2_linux_amd64 /usr/local/bin/php-fpm_exporter
       chmod 755 /usr/local/bin/php-fpm_exporter
    
  4. In your PHP-FPM Config, uncomment the listen mode (if it is commented out):
    vim /etc/php/7.2/fpm/pool.d/www.conf
    Uncomment out this line: #listen.mode = 0666

  5. Create a service for the PHP-FPM exporter:
    vim /etc/systemd/system/php-fpm_exporter.service

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    # Service file for PHP FPM Exporter:
    [Unit]
    Description=PHP FPM Exporter Service
    After=network.target
    
    [Service]
    User=nginx
    Group=nginx
    Type=simple
    ExecStart=/usr/local/bin/php-fpm_exporter server --phpfpm.scrape-uri "unix:///var/run/php/php7.2-fpm.sock;/status"
    
    [Install]
    WantedBy=multi-user.target
    
  6. Reload and start up your services:

    1
    2
    3
    4
    
    sudo systemctl daemon-reload
    sudo systemctl enable php-fpm_exporter
    sudo systemctl start php-fpm_exporter
    sudo systemctl status php-fpm_exporter
    

And that's pretty much it. The bit that caught me out was the listen mode - which was commented out by default.