Skip to content

PHP-FPM

·


PHP-FPM collector is used for PHP-FPM metrics collection, such as the number of active processes, total number of idle processes, the number of requests in the queue of pending connections, the maximum number of active processes, etc.

Configuration

Preconditions

  1. Enable PHP-FPM status page

    • Edit the PHP-FPM configuration file(typically located at /etc/php/8.x/fpm/pool.d/www.conf or /etc/php-fpm.d/www.conf ). Enable pm.status_path :

    shell ; Enable status page pm.status_path = /status

    • Restart PHP-FPM

shell sudo systemctl restart php-fpm sudo systemctl restart php8.x-fpm

  1. Configure Web Server

    • Nginx example:
    location /status {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php8.x-fpm.sock; // unix socket mode
        # fastcgi_pass 127.0.0.1:9000; // TCP mode
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    
    • Restart Nginx:
    sudo systemctl restart nginx
    
    • Access the status page( /status ) to ensure it returns PHP-FPM status data correctly

Collector Configuration

Go to the conf.d/phpfpm directory under the DataKit installation directory, copy phpfpm.conf.sample and name it phpfpm.conf. Examples are as follows:

[[inputs.phpfpm]]
  ##(optional) collect interval, default is 10 seconds
  interval = '10s'

  ## URL to fetch PHP-FPM pool metrics. Defaults to HTTP (e.g., http://localhost/status).
  ## For TCP (e.g., tcp://127.0.0.1:9000/status) or Unix socket (e.g., unix:///run/php/php-fpm.sock;/status),
  ## set use_fastcgi to true.
  status_url = "http://localhost/status"

  ## (optional) use fastcgi, default is false (use http)
  use_fastcgi = false

  ## Set true to enable election
  election = true

  [inputs.phpfpm.tags]
    # some_tag = "some_value"
    # more_tag = "some_other_value"

Adjust the following configurations according to your environment: - When using the HTTP by default (e.g., http://localhost/status),keep use_fastcgi = false - When using Unix socket or TCP : * Address formats: unix:///socket/path;/status or tcp://ip:port/status * Must set use_fastcgi = true

Once configured, restart DataKit.

Can be turned on by ConfigMap Injection Collector Configuration or Config ENV_DATAKIT_INPUTS .

Can also be turned on by environment variables, (needs to be added as the default collector in ENV_DEFAULT_ENABLED_INPUTS):

  • ENV_INPUT_PHPFPM_INTERVAL

    Collect interval

    Type: Duration

    input.conf: interval

    Default: 10s

  • ENV_INPUT_PHPFPM_STATUS_URL

    URL to fetch PHP-FPM pool metrics (HTTP or FastCGI)

    Type: String

    input.conf: status_url

    Default: http://localhost/status

  • ENV_INPUT_PHPFPM_USE_FAST_C_G_I

    Use FastCGI protocol instead of HTTP to fetch metrics

    Type: Boolean

    input.conf: use_fast_c_g_i

    Default: false

Metric

For all of the following data collections, the global election tags will added automatically, we can add extra tags in [inputs.phpfpm.tags] if needed:

 [inputs.phpfpm.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"
  # ...

phpfpm

Tags & Fields Description
address
(tag)
Pool Address.
pid
(tag)
The pid of the process.
pool
(tag)
The Pools Name of the FPM.
process_manager
(tag)
The type of the Process Manager (static, dynamic, ondemand).
process_state
(tag)
The state of the process (Idle, Running, ...).
accepted_connections The number of requests accepted by the pool.
Type: int
Unit: count
active_processes The number of active processes.
Type: int
Unit: count
idle_processes The number of idle processes.
Type: int
Unit: count
listen_queue The number of requests in the queue of pending connections.
Type: int
Unit: count
listen_queue_length The size of the socket queue of pending connections.
Type: float
Unit: count
max_active_processes The maximum number of active processes since FPM has started.
Type: int
Unit: count
max_children_reached The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').
Type: int
Unit: count
max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.
Type: int
Unit: count
process_last_request_cpu The %cpu the last request consumed.
Type: float
Unit: percent,percent
process_last_request_memory The max amount of memory the last request consumed.
Type: int
Unit: count
process_request_duration The duration in microseconds of the requests.
Type: int
Unit: time,μs
process_requests The number of requests the process has served.
Type: int
Unit: count
slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.
Type: int
Unit: count
total_processes The number of idle + active processes.
Type: int
Unit: count

Feedback

Is this page helpful? ×