- Supports auto discovery of PHP-FPM pools (LLD) and automatic detection of sockets used by pools
- Supports multiple PHP-FPM pools
- Supports multiple PHP versions, i.e. you can use PHP 7.2 and PHP 7.3 on the same server and we will detect them all
- Easy configuration
- Supports ISPConfig
- Script is in pure bash: no need to install Perl, PHP, Go or other languages.
## Provided Items
We capture only useful data from host and PHP-FPM status page:
- Number of CPUs
- For each pool:
- **Accepted Connections Per Second** - the number of requests accepted by the pool
- **Active Processes** - the number of active processes
- **Idle Processes** - the number of idle processes
- **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`)
- **CPU Utilization** - CPU load for all processes of the pool in %
- **CPU Average Utilization** - CPU load for all processes of the pool in % normalized by number of CPUs
- **Listen Queue** - the number of requests in the queue of pending connections
- **Max Listen Queue** - the maximum number of requests in the queue of pending connections since FPM has started
- **Listen Queue Length** - the size of the socket queue of pending connections
- **Queue Utilization** - queue usage in %
- **Memory Used** - how much RAM used by the pool in bytes
- **Memory Utilization** - how much RAM used by the pool in %
- **Process Manager** - `dynamic`, `ondemand` or `static`, see [PHP manual](https://www.php.net/manual/en/install.fpm.configuration.php#pm).
- **Slow Requests** - the number of requests that exceeded your [`request_slowlog_timeout`](https://www.php.net/manual/en/install.fpm.configuration.php#request-slowlog-timeout) value.
- **Start Since** - number of seconds since FPM has started
- **Start Time** - the date and time FPM has started
History storage period is from 1 hour to 1 day (depends on specific item), trend storage period is 365 days that's optimal for environments with multiple websites.
Data is captured every minute. These timings can be adjusted in template or per host if needed.
Automatic detection of pools requires root previliges. You can achieve it using one of the methods below.
##### 1.3.1 Root previliges for Zabbix Agent
This method sets root previliges for Zabbix Agent, i.e. the Zabbix Agent will run under `root` user, as a result all user scripts will also have the root access rights.
##### 1.3.2 Grant previliges to the PHP-FPM autodiscovery script only
If you don't want to run Zabbix Agent as root, then you can configure the previliges only to our script. In this case you need to have `sudo` installed:
```console
apt-get install sudo
```
Now edit the `/etc/sudoers` file by running command:
```console
visudo
```
Add the following line to this file:
```
zabbix ALL = NOPASSWD: /etc/zabbix/zabbix_php_fpm_discovery.sh
Here we specified `zabbix` as the user under which the Zabbix Agent is run. This is the default name, but if you have a custom installation with different name, then please, change it accordingly. Save and exit the editor. Your modifications will be applied.
Now edit the file `userparameter_php_fpm.conf`. Find the line:
Usually PHP-FPM [backlog option](https://www.php.net/manual/en/install.fpm.configuration.php#listen-backlog) is limited by Linux kernel settings and equals to `128` by default.
In most cases you want to increase this value (latest PHP use `511` by default).
The main option that limits the PHP-FPM backlog option is `net.core.somaxconn`.
Now we can cause the settings to be loaded by running:
```console
sysctl -p
```
#### 1.5. Adjust ISPConfig
This step is required only if you use [ISPConfig](https://www.ispconfig.org/).
ISPConfig does not enable PHP-FPM status page by default.
We will enable it by adding a custom PHP-FPM configuration template.
This file is an original configuration file from [ISPConfig v.3.1.14p2](https://www.ispconfig.org/blog/ispconfig-3-1-14p2-released-important-security-bugfix/), it only enables the status page by adding the following line:
```
pm.status_path = /php-fpm-status
```
Copy the configuration file into ISPConfig custom configuration directory:
In this case you need to enable the PHP-FPM status page for all of your pools manually.
Each pool must have the same status path, recommended value is `/php-fpm-status`.
Please, edit all the pools configuration files (for example for PHP 7.3 they are located in directory `/etc/php/7.3/fpm/pool.d`) by adding the following line:
```
pm.status_path = /php-fpm-status
```
You can set another path here if needed. Finally, restart the PHP-FPM, for example:
**Important:** please make sure that you use `bash` in the command above, not `sh` or other alternatives, otherwise you may get a script syntax error message.
If this script does not display the list, then it will show you the list of utilities that are missing on your system and must be installed. We require the following utilities to be installed:
- awk
- ps
- grep
- sort
- head
- lsof
- jq
If some pools are missing, then check that they do really exist and are running, for example, using command:
```console
ps aux | grep "php-fpm"
```
In the list you should see your pool. If it's not there, then it means it's not running (not functional).
Please, use the [`zabbix_get`](https://www.zabbix.com/documentation/4.4/manual/concepts/get) utility from your Zabbix Server to test that you can get the data from the Zabbix Agent (host):
-`127.0.0.1` is the IP address of the host where the Zabbix Agent is installed and where the PHP-FPM is running
-`10050` is the port of the Zabbix Agent
-`POOL_URL` is the socket of the pool or IP and port combination, example: `/var/lib/php7.3-fpm/web1.sock` or `127.0.0.1:9000`
-`POOL_PATH` is the status path of PHP-FPM that you set in [`pm.status_path`](https://github.com/rvalitov/zabbix-php-fpm#16-adjust-php-fpm-pools-configuration), the default value is `/php-fpm-status`.
The commands above should return valid JSON data. If any error happens then it will be displayed.
Should work with PHP 5.6.x and later, Zabbix 4.2.x and later. Currently the template does not work with Zabbix 4.0.x, see [issue](https://github.com/rvalitov/zabbix-php-fpm/issues/5).
Not tested with other versions of Zabbix: if it works, please let me know.