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-fpmservice php-fpm restart添加nginx的配置打开/usr/local/nginx/conf/nginx.conflocation ~ \.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-agentservice zabbix-agent restart测试zabbix_get -s 127.0.0.1 -k slow.requests如果没有问题导入模板php-fpm_status.xml现在就能看到数据了脚本和模板如下:
vim php-fpm_status.sh #!/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
vim php-fpm_status.conf 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