Datadog php-fpm monitoring via nginx

It took me some time to get this set up properly, but here are my configs that finally worked to get php-fpm monitoring using datadog.

1. nginx vhost config

First, make sure you override your site’s hostname to localhost. For my site this is to make sure connections don’t go out to cloudflare but stay local on the server: /etc/hosts needs to contain this line.

I use my port 80 vhost config for the status page. Cloudflare enforces SSL so this vhost never gets used for anything non-local on my server.

server {
  listen 80;
  listen [::]:80;
  access_log /var/log/nginx/ main;
  error_log /var/log/nginx/ error;
  location ~ ^/(status|ping) {
    access_log off;
    deny all;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

I use “” as fastcgi_pass value. This is defined in another file on the conf.d dir and matches the socket definition in the php-fpm pool config file.


upstream {
 server unix:/var/run/php-fpm/;

(This setup is inspired by Mattias’ config for the Nucleus customers)

2. php-fpm pool config

Make sure these 3 lines are present in your php-fpm pool config:

pm.status_path = /status
ping.path = /ping
ping.response = pong

Normally your acl should be fine as requests will come from localhost.

3. Datadog config file

So nginx and php-fpm are configured, all we have left is the datadog config file:


 - # Get metrics from your FPM pool with this URL
   # Get a reliable service check of your FPM pool with that one
   # Set the expected reply to the ping.
   ping_reply: pong

Reload nginx, php-fpm and datadog-agent after that and your php-fpm tracking should now work. This tracks only 1 pool, it’s up to you to figure out how to track multiple pools now :)

comments powered by Disqus