当前位置: > Linux服务器 > 监控工具 >

zabbix监控nginx、php-fpm的状态

时间:2015-01-17 02:13来源:linux.it.net.cn 作者:IT

添加脚本之前,需要将所监控php-fpm需要在nginx内配置php-fpm的状态并转发出来,nginx内配置如下配置完成后,可以打开浏览器查看下状态,是否可以正常访问

配置完成后,将脚本放在所需要监控的机器上面,模板导入到web即可

nginx配置如下:

server {

    listen 40080;
    server_name _;
    allow 127.0.0.1;
    deny all;
    access_log off;
    location /php-fpm_status {
    fastcgi_pass unix:/tmp/php-fpm.sock;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

    }

location /nginx_status { #这里配置的是nginx的状态,和php-fpm的监控一样

   stub_status on;

   }

}

 

脚本:

 


	
#########################################################################
# File Name: php-fpm_status.sh
# Author: kerncai
# mail: kernkerncai@gmail.com
# Created Time: 2013年11月13日 星期三 14时02分35秒
#########################################################################
#!/bin/bash
idle(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "idle processes" |awk '{print$3}'
}
 
total(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "total processes" |awk '{print$3}'
}
 
active(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "active" |awk '{print$3}'|grep -v "process"
}
 
mactive(){
 
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "max active processes:" |awk '{print$4}'
}
 
listenqueuelen(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue len" |awk '{print$4}'
}
 
listenqueue(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'
}
 
since(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "start since: " |awk '{print$3}'
}
 
conn(){
        wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "accepted conn" |awk '{print$3}'
}
$1
 

zabbix.agentd.conf的配置文件如下 :

UnsafeUserParameters=1(自定义脚本必开)

UserParameter=idle.processe,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh idle UserParameter=total.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh total UserParameter=active.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh active UserParameter=max.active.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh mactive UserParameter=listen.queue.len,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh listenqueuelen UserParameter=listen.queue,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh listenqueue UserParameter=start.since,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh since UserParameter=accepted.conn,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh conn

模板的话根据配置文件创建,本来向贴个github的链接的,不过貌似csdn不给贴链接 ~~~ https://github.com/kerncai/zabbix  github 上面有模板和脚本~

个人博客:http://www.kerncai.com/

(责任编辑:IT)
------分隔线----------------------------