zabbix监控php-fpm的性能
zabbix监控php-fpm主要是通过nginx配置php-fpm的状态输出页面,在正则取值
要nginx能输出php-fpm的状态必须要先修改php-fpm的配置,这个配置没有开启nginx 就没有办法输出php-fpm status
修改/usr/local/php/etc/php-fpm.conf 文件
注意:不是php.ini,如果没有配置添加配置
pm.status_path = /status
重启php-fpm
service php-fpm restart
添加nginx的配置
打开/usr/local/nginx/conf/nginx.conf
|
1
2
3
4
5
6
7
8
|
location ~ \.php|^/status$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_connect_timeout 180;fastcgi_read_timeout 600;fastcgi_send_timeout 600;include fastcgi.conf;} |
配置好之后重启一下nginx
service nginx restart

添加监控的shlle脚本
php-fpm_status.sh
添加zabbix-agent配置
php-fpm_status.conf
重启zabbix-agent
service zabbix-agent restart
测试
zabbix_get -s 127.0.0.1 -k slow.requests
如果没有问题导入模板
php-fpm_status.xml
现在就能看到数据了

脚本和模板如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
vim php-fpm_status.sh<br>#!/bin/bashlistenqueue(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'}listenqueuelen(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue len" |awk '{print$4}'}idle(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "idle processes" |awk '{print$3}'}active(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "active" |awk '{print$3}'|grep -v "process"}total(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "total processes" |awk '{print$3}'}mactive(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max active processes:" |awk '{print$4}'}since(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "start since: " |awk '{print$3}'}conn(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "accepted conn" |awk '{print$3}'}reached(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max children reached" |awk '{print$4}'}requests(){ wget --quiet -O - http://127.0.0.1:80/status?auto |grep "slow requests" |awk '{print$3}'}$1 |
|
1
2
3
4
5
6
7
8
9
10
|
vim php-fpm_status.conf<br>UserParameter=idle.processe,/scripts/php-fpm_status.sh idleUserParameter=total.processes,/scripts/php-fpm_status.sh totalUserParameter=active.processes,/scripts/php-fpm_status.sh activeUserParameter=max.active.processes,/scripts/php-fpm_status.sh mactiveUserParameter=listen.queue.len,/scripts/php-fpm_status.sh listenqueuelenUserParameter=listen.queue,/scripts/php-fpm_status.sh listenqueueUserParameter=start.since,/scripts/php-fpm_status.sh sinceUserParameter=accepted.conn,/scripts/php-fpm_status.sh connUserParameter=max.children.reached,/scripts/php-fpm_status.sh reachedUserParameter=slow.requests,/scripts/php-fpm_status.sh requests |

浙公网安备 33010602011771号