zabbix3.2学习笔记(六):自定义监控nginx+php-fpm status

zabbix自带了一些模版,可根据需要修改对应监控项的阈值;可是像nginx/ph-fpm/redis/mysql等一些应用还需要我们自定义监控项、用脚本在客户端取值。下面简单监控nginx和php-fpm的状态:二者本身自带status参数,只需开启即可。

1,开启status

vi /etc/php-fpm.conf 尾部添加一行
pm.status_path = /php-fpm_status

cd /etc/nginc/conf.d/
vi nginxphp_status.conf
server {

listen 40080;
allow 127.0.0.1;
deny all;
access_log off;
location /php-fpm_status {
     fastcgi_pass 127.0.0.1:9000;
      include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}

location /nginx_status {
      stub_status on;
}
}

service php-fpm restart
service nginx restart

curl -s http://127.0.0.1:40080/nginx_status
Active connections: 1
server accepts handled requests
6 6 6
Reading: 0 Writing: 1 Waiting: 0

nginx status详解
active connections – 活跃的连接数
server accepts handled requests — 总共处理了6个连接 , 成功创建6次握手, 总共处理了6个请求
reading — 读取客户端的连接数
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。所以,在访问效率高,请求很快被处理完毕的情况下,Waiting数比较多是正常的.如果reading +writing数较多,则说明并发访问量非常大,正在处理过程中。

curl -s http://127.0.0.1:40080/php-fpm_status
pool: www
process manager: dynamic
start time: 17/Aug/2017:17:09:32 +0800
start since: 64
accepted conn: 2
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
slow requests: 0

php-fpm status详解
pool – fpm池子名称,大多数为www 
process manager – 进程管理方式,值:static, dynamic or ondemand. dynamic 
start time – 启动日期,如果reload了php-fpm,时间会更新 
start since – 运行时长 
accepted conn – 当前池子接受的请求数 
listen queue – 请求等待队列,如果这个值不为0,那么要增加FPM的进程数量 
max listen queue – 请求等待队列最高的数量 
listen queue len – socket等待队列长度 
idle processes – 空闲进程数量 
active processes – 活跃进程数量 
total processes – 总进程数量 
max active processes – 最大的活跃进程数量(FPM启动开始算) 
max children reached - 大道进程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量大小了,需改大一点。 
php-fpm状态页可以通过带参数实现个性化,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。
json格式:http://127.0.0.1:40080/php-status?json
xml格式: http://127.0.0.1:40080/php-status?xml
html 格式: http://127.0.0.1:40080/php-status?html 
full格式: http://127.0.0.1:40080/php-status?ful

2,在zabbix agent端新建shell脚本来取值
cd /etc/zabbix/zabbix_agentd.d
vi php-fpm_status.sh

#!/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

vi nginx_status.sh

#!/bin/bash

Active(){
        wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==1 {print$3}'
}
Reading(){
        wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$2}'
}
Writing(){
        wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$4}'
}
Waiting(){
        wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$6}'
}
$1
3,修改/etc/zabbix/zabbix_agentd.conf添加一下内容
UnsafeUserParameters=1 

UserParameter=idle.processe,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh idle
UserParameter=total.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh total
UserParameter=active.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh active
UserParameter=max.active.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh mactive
UserParameter=listen.queue.len,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh listenqueuelen
UserParameter=listen.queue,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh listenqueue
UserParameter=start.since,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh since
UserParameter=accepted.conn,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh conn

UserParameter=Active,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Active
UserParameter=Reading,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Reading
UserParameter=Writing,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Writing
UserParameter=Waiting,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Waiting

service zabbix-agent restart

4,在zabbix web端导入以下模版
http://pan.baidu.com/s/1bp3wJYf

将主机关联以上模版,随后在最新数据里查看是否收集到监控值

github上搜索zabbix会看到很多开源的监控模版,挑你需要的试试吧

转载于:https://my.oschina.net/u/3649203/blog/1525524

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值