zabbix监控php
一、开启php-fpm的status页面,此页面跟nginx的stub_status页面类似,记录着php运行状态信息
大安市网站建设公司创新互联,大安市网站设计制作,有大型网站制作公司丰富经验。已为大安市上千多家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的大安市做网站的公司定做!
# cat /etc/php-fpm.d/www.conf pm.status_path = /status
二、配置nginx代理访问php的status页面
# cat /etc/nginx/conf.d/nginx_status.conf server { listen 80 default ; server_name _ ; location = /status { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; \\此选项必须添加,不添加采集不到数据 access_log off; allow 127.0.0.1; deny all ; }
三、访问测试,确保可以访问到php的status的页面数据
# curl http://127.0.0.1/status pool: www process manager: dynamic start time: 31/3月/2016:22:29:27 +0800 start since: 489290 accepted conn: 3 listen queue: 0 max listen queue: 0 listen queue len: 128 idle processes: 4 active processes: 1 total processes: 5 max active processes: 1 max children reached: 0
四、在agent端编写shell脚本,采集php的status页面信息;脚本路径存放在/opt/zabbix/script/目录下
# vim php_fpm_status.sh #!/bin/bash AcceptedConn(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/accepted conn/{print $2}' |awk '{print $1}' } ListenQueue(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/listen queue/{print $2}' |awk '{print $1}' } MaxListenQueue(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/max listen queue/{print $2}' |awk '{print $1}' } ListenQueueLen(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/listen queue len/{print $2}'|awk '{print $1}' } IdleProcesses(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/idle processes/{print $2}'|awk '{print $1}' } ActiveProcesses(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/active processes/{print $2}'|awk '{print $1}' } TotalProcesses(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/total processes/{print $2}'|awk '{print $1}' } MaxActiveProcesses(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/max active processes/{print $2}' |awk '{print $1}' } MaxChildrenReached(){ curl http://127.0.0.1/zphp_status 2>/dev/null | awk -F ":" '/max children reached/{print $2}' |awk '{print $1}' } $1 # chmod +x php_fpm_status.sh \\添加执行权限
五、在agent端,创建key、value;位置在opt/zabbix/etc/zabbix_agentd.conf.d/目录下
# vim php-fpm-nginx.conf UserParameter=active.conn, /opt/zabbix/script/php_fpm_status.sh AcceptedConn UserParameter=listen.queue, /opt/zabbix/script/php_fpm_status.sh ListenQueue UserParameter=max.listen.queue, /opt/zabbix/script/php_fpm_status.sh MaxListenQueue UserParameter=listen.queue.len,/opt/zabbix/script/php_fpm_status.sh ListenQueueLen UserParameter=idle.processes, /opt/zabbix/script/php_fpm_status.sh IdleProcesses UserParameter=active.processes, /opt/zabbix/script/php_fpm_status.sh ActiveProcesses UserParameter=total.processes, /opt/zabbix/script/php_fpm_status.sh TotalProcesses UserParameter=max.active.processes, /opt/zabbix/script/php_fpm_status.sh MaxActiveProcesses UserParameter=max.children.reached, /opt/zabbix/script/php_fpm_status.sh MaxChildrenReached # /etc/init.d/zabbix_agentd restart \\上述配置完成后,重启agentd服务
六、在server端利用zabbix_get获取测试数据,查看配置是否成功
# zabbix_get -s 172.16.100.17 -p 10050 -k "active.conn" 42
七、以上操作成功后,在zabbix的web页面创建php模板
1)创建模板
2)创建应用集
3)创建项目
4)创建图形
5)将此模板关联主机,查看获取的数据
到此,可以安心的边喝茶边观察php的状态了。
文章名称:zabbix监控php
文章URL:http://myzitong.com/article/iggcds.html