zabbix监控php-fpm的性能

zabbix经过自定义item监控php-fpm性能状况作触发器,作图形,发邮件php

首先php-fpm的性能数据是要经过页面获取,因此须要在php-fpm的配置文件中添加一下语句html

通常在/usr/local/php/etc/php-fpm.confnginx

pm.status_path = /statusjson

重启php-fpmvim

在nginx的配置文件中加入页面匹配bash

/usr/local/nginx/conf/nginx.confcurl

location ~ ^/(status|ping)$
    {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; socket

}php-fpm

重启nginx性能

curl http://127.0.0.1/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,那说明你的最大进程数量过小了,请改大一点。
slow requests – 启用了php-fpm slow-log,缓慢请求的数量

php-fpm状态页比较个性化的一个地方是它能够带参数,能够带参数json、xml、html而且前面三个参数能够分别和full作一个组合。用了以上参数能够得到知道格式的页面

curl http://127.0.0.1/status?json

curl http://127.0.0.1/status?xml

curl http://127.0.0.1/status?html

curl http://127.0.0.1/status?full

参数full详解

pid – 进程PID,能够单独kill这个进程. You can use this PID to kill a long running process.
state – 当前进程的状态 (Idle, Running, …)
start time – 进程启动的日期
start since – 当前进程运行时长
requests – 当前进程处理了多少个请求
request duration – 请求时长(微妙)
request method – 请求方法 (GET, POST, …)
request URI – 请求URI
content length – 请求内容长度 (仅用于 POST)
user – 用户 (PHP_AUTH_USER) (or ‘-’ 若是没设置)
script – PHP脚本 (or ‘-’ if not set)
last request cpu – 最后一个请求CPU使用率。
last request memorythe - 上一个请求使用的内存

接着经过自定义item,加脚本,模板就能够经过zabbix监控性能

添加监控的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

脚本

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
 
 
模板
vim php-fpm_status.conf
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
 
接着就能够根据item建立图形,根据值建立触发器,根据触发器发送邮件或进一步作脚本操做
UserParameter=slow.requests, /scripts/php-fpm_status .sh requests
相关文章
相关标签/搜索