PHP-FPM

PHP-FPM

PHP FastCGI Process Manager (PHP-FPM) is an alternative FastCGI daemon for PHP that allows a website to handle high loads. PHP-FPM maintains pools (workers that can respond to PHP requests) to accomplish this. PHP-FPM is faster than traditional CGI-based methods, such as SUPHP, for multi-user PHP environments.

Available solutions




Source: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/app/php-fpm_http


Template App PHP-FPM by HTTP

Overview

For Zabbix version: 5.0
The template to monitor PHP-FPM by Zabbix that work without any external scripts. Most of the metrics are collected in one go, thanks to Zabbix bulk data collection.

Template App PHP-FPM by HTTP collects metrics by polling PHP-FPM status-page with HTTP agent remotely.

Note that this solution supports https and redirects.

This template was tested on:

  • PHP, version 7

Setup

See Zabbix template operation for basic instructions.

  1. Open the php-fpm configuration file and enable the status page as shown.

    pm.status_path = /status
    ping.path = /ping
  2. Validate the syntax is fine before we reload the service

    $ php-fpm7 -t
  3. Reload the php-fpm service to make the change active

    $ systemctl reload php-fpm
  4. Next, edit your Nginx server block (virtual host) configuration file and add the location block below in it.

    # Enable php-fpm status page
    location ~ ^/(status|ping)$ {
    ## disable access logging for request if you prefer
    access_log off;
    
    ## Only allow trusted IPs for security, deny everyone else
    # allow 127.0.0.1;
    # allow 1.2.3.4;    # your IP here
    # deny all;
    
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    include fastcgi_params;
    ## Now the port or socket of the php-fpm pool we want the status of
    fastcgi_pass 127.0.0.1:9000;
    # fastcgi_pass unix:/run/php-fpm/your_socket.sock;
    }
  5. Check the syntax $ nginx -t

  6. Reload Nginx $ systemctl reload nginx

  7. Verify curl -L 127.0.0.1/status

If you use another location of status/ping page, don't forget to change {$PHP_FPM.STATUS.PAGE}/{$PHP_FPM.PING.PAGE} macro.

If you use an atypical location for PHP-FPM status-page don't forget to change the macros {$PHP_FPM.SCHEME},{$PHP_FPM.PORT}.

Zabbix configuration

No specific Zabbix configuration is required.

Macros used

Name Description Default
{$PHP_FPM.HOST}

Hostname or IP of PHP-FPM status host or container.

localhost
{$PHP_FPM.PING.PAGE}

The path of PHP-FPM ping page.

ping
{$PHP_FPM.PING.REPLY}

Expected reply to the ping.

pong
{$PHP_FPM.PORT}

The port of PHP-FPM status host or container.

80
{$PHP_FPM.QUEUE.WARN.MAX}

The maximum PHP-FPM queue usage percent for trigger expression.

80
{$PHP_FPM.SCHEME}

Request scheme which may be http or https

http
{$PHP_FPM.STATUS.PAGE}

The path of PHP-FPM status page.

status

Template links

There are no template links in this template.

Discovery rules

Items collected

Group Name Description Type Key and additional info
PHP-FPM PHP-FPM: Ping

-

DEPENDENT php-fpm.ping

Preprocessing:

- REGEX: {$PHP_FPM.PING.REPLY}$ 1

⛔️ON_FAIL: CUSTOM_VALUE -> 0

PHP-FPM PHP-FPM: Processes, active

The total number of active processes.

DEPENDENT php-fpm.processes_active

Preprocessing:

- JSONPATH: $.['active processes']

PHP-FPM PHP-FPM: Version

Current version PHP. Get from HTTP-Header "X-Powered-By" and may not work if you change default HTTP-headers.

DEPENDENT php-fpm.version

Preprocessing:

- REGEX: ^[.\s\S]*X-Powered-By: PHP/([.\d]{1,}) \1

⛔️ON_FAIL: DISCARD_VALUE ->

- DISCARD_UNCHANGED_HEARTBEAT: 3h

PHP-FPM PHP-FPM: Pool name

The name of current pool.

DEPENDENT php-fpm.name

Preprocessing:

- JSONPATH: $.pool

- DISCARD_UNCHANGED_HEARTBEAT: 3h

PHP-FPM PHP-FPM: Uptime

How long has this pool been running.

DEPENDENT php-fpm.uptime

Preprocessing:

- JSONPATH: $.['start since']

PHP-FPM PHP-FPM: Start time

The time when this pool was started.

DEPENDENT php-fpm.start_time

Preprocessing:

- JSONPATH: $.['start time']

PHP-FPM PHP-FPM: Processes, total

The total number of server processes currently running.

DEPENDENT php-fpm.processes_total

Preprocessing:

- JSONPATH: $.['total processes']

PHP-FPM PHP-FPM: Processes, idle

The total number of idle processes.

DEPENDENT php-fpm.processes_idle

Preprocessing:

- JSONPATH: $.['idle processes']

PHP-FPM PHP-FPM: Process manager

The method used by the process manager to control the number of child processes for this pool.

DEPENDENT php-fpm.process_manager

Preprocessing:

- JSONPATH: $.['process manager']

- DISCARD_UNCHANGED_HEARTBEAT: 3h

PHP-FPM PHP-FPM: Processes, max active

The highest value that 'active processes' has reached since the php-fpm server started.

DEPENDENT php-fpm.processes_max_active

Preprocessing:

- JSONPATH: $.['max active processes']

PHP-FPM PHP-FPM: Accepted connections per second

The number of accepted requests per second.

DEPENDENT php-fpm.conn_accepted.rate

Preprocessing:

- JSONPATH: $.['accepted conn']

- CHANGE_PER_SECOND

PHP-FPM PHP-FPM: Slow requests

The number of requests that exceeded your request_slowlog_timeout value.

DEPENDENT php-fpm.slow_requests

Preprocessing:

- JSONPATH: $.['slow requests']

- SIMPLE_CHANGE

PHP-FPM PHP-FPM: Listen queue

The current number of connections that have been initiated, but not yet accepted.

DEPENDENT php-fpm.listen_queue

Preprocessing:

- JSONPATH: $.['listen queue']

PHP-FPM PHP-FPM: Listen queue, max

The maximum number of requests in the queue of pending connections since this FPM pool has started.

DEPENDENT php-fpm.listen_queue_max

Preprocessing:

- JSONPATH: $.['max listen queue']

PHP-FPM PHP-FPM: Listen queue, len

Size of the socket queue of pending connections.

DEPENDENT php-fpm.listen_queue_len

Preprocessing:

- JSONPATH: $.['listen queue len']

PHP-FPM PHP-FPM: Queue usage

Queue utilization

CALCULATED php-fpm.listen_queue_usage

Expression:

last(php-fpm.listen_queue)/(last(php-fpm.listen_queue_len)+last(php-fpm.listen_queue_len)=0)*100
PHP-FPM PHP-FPM: Max children reached

The number of times that pm.max_children has been reached since the php-fpm pool started

DEPENDENT php-fpm.max_children

Preprocessing:

- JSONPATH: $.['max children reached']

- SIMPLE_CHANGE

Zabbix_raw_items PHP-FPM: Get ping page

-

HTTP_AGENT php-fpm.get_ping
Zabbix_raw_items PHP-FPM: Get status page

-

HTTP_AGENT php-fpm.get_status

Triggers

Name Description Expression Severity Dependencies and additional info
PHP-FPM: Service is down

-

{TEMPLATE_NAME:php-fpm.ping.last()}=0 or {TEMPLATE_NAME:php-fpm.ping.nodata(3m)}=1 HIGH

Manual close: YES

PHP-FPM: Version has changed (new version: {ITEM.VALUE})

PHP-FPM version has changed. Ack to close.

{TEMPLATE_NAME:php-fpm.version.diff()}=1 and {TEMPLATE_NAME:php-fpm.version.strlen()}>0 INFO

Manual close: YES

PHP-FPM: Failed to fetch info data (or no data for 30m)

Zabbix has not received data for items for the last 30 minutes

{TEMPLATE_NAME:php-fpm.uptime.nodata(30m)}=1 INFO

Manual close: YES

Depends on:

- PHP-FPM: Service is down

PHP-FPM: has been restarted (uptime < 10m)

Uptime is less than 10 minutes

{TEMPLATE_NAME:php-fpm.uptime.last()}<10m INFO

Manual close: YES

PHP-FPM: Manager changed (new value received: {ITEM.VALUE})

PHP-FPM manager changed. Ack to close.

{TEMPLATE_NAME:php-fpm.process_manager.diff()}=1 INFO

Manual close: YES

PHP-FPM: Detected slow requests

PHP-FPM detected slow request. A slow request means that it took more time to execute than expected (defined in the configuration of your pool).

{TEMPLATE_NAME:php-fpm.slow_requests.min(#3)}>0 WARNING
PHP-FPM: Queue utilization is high (over {$PHP_FPM.QUEUE.WARN.MAX}% for 15m)

The queue for this pool reached {$PHP_FPM.QUEUE.WARN.MAX}% of its maximum capacity. Items in queue represent the current number of connections that have been initiated on this pool, but not yet accepted.

{TEMPLATE_NAME:php-fpm.listen_queue_usage.min(15m)} > {$PHP_FPM.QUEUE.WARN.MAX} WARNING

Feedback

Please report any issues with the template at https://support.zabbix.com

Articles and documentation

+ Propose new article
Add your solution