├── LICENSE ├── README.md ├── Zabbix_Template_Php-Fpm.xml ├── img ├── macros.png └── metrics.png ├── php-fpm.discover_pools.pl └── userparameter_php-fpm.conf /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 vigrai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zabbix 4.0 Template for PHP-FPM Pools 2 | 3 | This is a template for monitoring php-fpm and it's pools with [Zabbix](www.zabbix.com). 4 | 5 | What's special about this template, is that it *automatically* detects (using LLD) the running php-fpm pools and creates items for measuring metrics from each pool. It uses Http Agent type check in zabbix in order to parse the php status information into useful metrics. 6 | 7 | So, if you are running a server with multiple php-fpm pools, this may be a better alternative for monitoring php than other templates available. 8 | 9 | # Compatibility 10 | 11 | This template was tested using: 12 | 13 | | Software | Vesion | 14 | | ------ | ------ | 15 | | Zabbix Server | 4.0.3 | 16 | | Debian | Stretch (9.8) | 17 | | Php-fpm | 7.2 | 18 | 19 | It might also work with other combination of versions. 20 | 21 | # Metrics 22 | 23 | This are the metrics created for each php-fpm pool: 24 | 25 | ![N|Solid](https://github.com/vigrai/zabbix-template-php-fpm/blob/master/img/metrics.png) 26 | 27 | # Requirements 28 | 29 | - Php-status should be enabled in the php-fpm pools. 30 | - Php-status should be accessible and located in /php-status_POOLNAME for each pool (see step 4 of Setup). 31 | 32 | # Setup 33 | 34 | Even though this template is made with automation in mind, there's still some manual steps to be done in the client (where php-fpm and zabbix-agent are running) in order to get it working: 35 | 36 | 1. Clone this template into a temporary directory. 37 | 38 | ``` 39 | # git clone https://github.com/vigrai/zabbix-template-php-fpm.git /tmp/zabbix-template 40 | ``` 41 | 42 | 2. Put the file `php-fpm.discover_pools.pl` into the /etc/zabbix directory and make it executable. 43 | 44 | ``` 45 | # cp /tmp/zabbix-template/php-fpm.discover_pools.pl /etc/zabbix 46 | # chmod +x /etc/zabbix/php-fpm.discover_pools.pl 47 | # chown zabbix.zabbix /etc/zabbix/php-fpm.discover_pools.pl 48 | ``` 49 | 3. Copy the file userparameter_php-fpm.conf into /etc/zabbix/zabbix_agentd.d. 50 | ``` 51 | # cp /tmp/zabbix-template/userparameter_php-fpm.conf /etc/zabbix/zabbix_agentd.d 52 | ``` 53 | 4. Make sure that your php-fpm is correctly setup: 54 | 55 | [x] The pools should have php-status enabled. 56 | 57 | [x] Php-status should be available in the path /fpm-status_[NAME-OF-THE-POOL] 58 | 59 | Example configuration file for pool called *nms* (/etc/php/7.2/fpm/pool.d/nms.conf): 60 | 61 | ```[nms]``` 62 | 63 | ```pm.status_path = /fpm-status_nms``` 64 | 65 | [x] Php-status should be accessible for each pool. This is an example configuration file for nginx: 66 | 67 | ``` 68 | ## Example configuration file for serving php-status of each php pool using nginx. 69 | # Take-aways: 70 | # 1.- The location should be in the format /fpm-status_POOLNAME 71 | # 2.- The proxy_pass should point to the correct pool. In this case unix sockets are used, but it'd be similar with a network connection (example: fastcgi_pass 127.0.0.1:9001). 72 | 73 | server { 74 | listen 0.0.0.0:8080; 75 | server_name status.localhost; 76 | 77 | keepalive_timeout 0; 78 | 79 | # Allow the ip of the Zabbix Proxy/Server which is going to perform the polling. 80 | # In this case, I am installing on the same host, so 127.0.0.1. 81 | allow 127.0.0.1; 82 | deny all; 83 | 84 | location /fpm-status_nms { 85 | include fastcgi_params; 86 | fastcgi_pass unix:/var/run/php/php7.2-nms-fpm.sock; 87 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 88 | } 89 | 90 | location /fpm-status_website1 { 91 | include fastcgi_params; 92 | fastcgi_pass unix:/var/run/php/php7.2-website1-fpm.sock; 93 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 94 | } 95 | 96 | location /fpm-status_website2 { 97 | include fastcgi_params; 98 | fastcgi_pass unix:/var/run/php/php7.2-website2-fpm.sock; 99 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 100 | } 101 | 102 | location /fpm-status_website3 { 103 | include fastcgi_params; 104 | fastcgi_pass unix:/var/run/php/php7.2-website3-fpm.sock; 105 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 106 | } 107 | 108 | access_log off; 109 | 110 | } 111 | ``` 112 | 5. Check that the script is finding the running pools: 113 | ``` 114 | # /etc/zabbix/php-fpm.discover_pools.pl 115 | { 116 | "data":[ 117 | 118 | { 119 | "{#POOLNAME}":"nms" 120 | } 121 | , 122 | { 123 | "{#POOLNAME}":"website1" 124 | } 125 | , 126 | { 127 | "{#POOLNAME}":"website2" 128 | } 129 | , 130 | { 131 | "{#POOLNAME}":"website3" 132 | } 133 | 134 | ] 135 | 136 | } 137 | ``` 138 | 6. If the script is returning the pools, you are ready to go. Import the zabbix-template-php-fpm.xml file in your Zabbix GUI and make sure that the macros are correctly setup, this are the values by default: 139 | ![N|Solid](https://github.com/vigrai/zabbix-template-php-fpm/blob/master/img/macros.png) 140 | -------------------------------------------------------------------------------- /Zabbix_Template_Php-Fpm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0 4 | 2019-02-20T19:21:01Z 5 | 6 | 7 | Templates/Applications 8 | 9 | 10 | 11 | 1265 | 1266 | 1267 | -------------------------------------------------------------------------------- /img/macros.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vigrai/zabbix-template-php-fpm/ca90ed372ff58305ef83aafa50b670ffe9d2c214/img/macros.png -------------------------------------------------------------------------------- /img/metrics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vigrai/zabbix-template-php-fpm/ca90ed372ff58305ef83aafa50b670ffe9d2c214/img/metrics.png -------------------------------------------------------------------------------- /php-fpm.discover_pools.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | $first = 1; 4 | 5 | print "{\n"; 6 | print "\t\"data\":[\n\n"; 7 | 8 | my $cmd = 'ps ax |grep "php-fpm: pool " |grep -v grep|awk \'{print $NF}\' |sort -u'; 9 | 10 | foreach $pool (`$cmd`) 11 | { 12 | print "\t,\n" if not $first; 13 | $first = 0; 14 | chomp $pool; 15 | 16 | print "\t{\n"; 17 | print "\t\t\"{#POOLNAME}\":\"$pool\"\n"; 18 | print "\t}\n"; 19 | } 20 | 21 | print "\n\t]\n"; 22 | print "}\n"; 23 | -------------------------------------------------------------------------------- /userparameter_php-fpm.conf: -------------------------------------------------------------------------------- 1 | UserParameter=php-fpm.discover_pools,/etc/zabbix/php-fpm.discover_pools.pl 2 | --------------------------------------------------------------------------------