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/bash listenqueue(){ 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 idle UserParameter=total.processes, /scripts/php-fpm_status .sh total UserParameter=active.processes, /scripts/php-fpm_status .sh active UserParameter=max.active.processes, /scripts/php-fpm_status .sh mactive UserParameter=listen.queue.len, /scripts/php-fpm_status .sh listenqueuelen UserParameter=listen.queue, /scripts/php-fpm_status .sh listenqueue UserParameter=start.since, /scripts/php-fpm_status .sh since UserParameter=accepted.conn, /scripts/php-fpm_status .sh conn UserParameter=max.children.reached, /scripts/php-fpm_status .sh reached UserParameter=slow.requests, /scripts/php-fpm_status .sh requests |
【推荐】FlashTable:表单开发界的极速跑车,让你的开发效率一路狂飙
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步