参考视频教程:
http://www.roncoo.com/course/view/fb3050a5b34b42f39ccad83ebebc89c1
龙果运维平台开源地址:https://github.com/roncoo/roncoo-cmdb
Php-fpm和nginx一样内建了一个状态页,对于想了解php-fpm的状态以及监控php-fpm非常有帮助。下面我们先来了解一下详情也的情况:
一、打开php-fpm详情页面:
Vim php-fpm.conf
pm.status_path = /13/status
二、修改nginx配置文件,打开/13/status的监控页面:
server {
listen 80;
server_name www.checkweb.com;
location /
{
root /home/www/web/bbs.chekcwev.com;
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
重启nginx,php-fpm
三、访问页面状态(我是用内网做host解析的,不用外网访问):
四、几个监控项目解析:
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,缓慢请求的数量
五、有编程语言基础,或者用curl访问的同学可以用json的方式返回json数据:
curl http://www.checkweb.com/13/status?json
六、具体脚本:
[root@BJ-monitor-h-01 scripts]# cat php-fpm_status.py
#coding=utf-8
import urllib,urllib2
import json,sys
def data_result():
try:
data = urllib2.urlopen("http://www.checkweb.com/13/status?json").read()
except urllib2.HTTPError as err:
print str(err)
data_ret = json.loads(data)
return data_ret
def accepted_conn():
data = data_result()
return data["accepted conn"]
def listen_queue():
data = data_result()
return data["listen queue"]
def max_listen_queue():
data = data_result()
return data["max listen queue"]
def listen_queue_len():
data = data_result()
return data["listen queue len"]
def idle_processes():
data = data_result()
return data["idle processes"]
def active_processes():
data = data_result()
return data["active processes"]
def total_processes():
data = data_result()
return data["total processes"]
def max_active_processes():
data = data_result()
return data["max active processes"]
def max_children_reached():
data = data_result()
return data["max children reached"]
def slow_requests():
data = data_result()
return data["slow requests"]
if __name__== "__main__":
if sys.argv[1]=="accepted_conn":
print accepted_conn()
if sys.argv[1]=="listen_queue":
print listen_queue()
if sys.argv[1]=="max_listen_queue":
print max_listen_queue()
if sys.argv[1]=="listen_queue_len":
print listen_queue_len()
if sys.argv[1]=="idle_processes":
print idle_processes()
if sys.argv[1]=="active_processes":
print active_processes()
if sys.argv[1]=="total_processes":
print total_processes()
if sys.argv[1]=="max_active_processes":
print max_active_processes()
if sys.argv[1]=="max_children_reached":
print max_children_reached()
if sys.argv[1]=="slow_requests":
print slow_requests()
七、配置zabbix 客户端:
[root@BJ-monitor-h-01 zabbix_agentd.conf.d]# cat php-fpm.conf
UserParameter=php-fpm.status[*],/usr/bin/python /usr/local/zabbix/scripts/php-fpm_status.py $1
八、web添加item的key选型:
**到此对于php-fpm的监控已经完成了。
关注微信: