使用用户自定义参数监控 php-fpm 服务的状态
在agent 端:
1、下载,设置php-fpm
[root@centos7 ~]# yum -y install php-fpm [root@centos7 ~]# vim /etc/php-fpm.d/www.conf # 打开php-fpm的状态页面
[root@node1 ~]# cat /etc/php-fpm.d/www.conf [www] user = nginx group = nginx listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 512 pm.start_servers = 32 pm.min_spare_servers = 32 pm.max_spare_servers = 64 pm.max_requests = 1500 pm.status_path = /php-fpm-status ##注意路径一会要用到 slowlog = /var/log/php-fpm/$pool-slow_log request_slowlog_timeout = 3 request_terminate_timeout = 20 catch_workers_output = no security.limit_extensions = ""
2、 开启 php-fpm 服务
[root@centos7 ~]# systemctl start php-fpm
3、设置 nginx 的配置文件,设置代理php,和php-fpm的状态页面匹配
安装一个nginx
yum -y install nginx
[root@node1 ~]# cat /etc/nginx/nginx.conf | grep -v "^[[:space:]].*#" | grep -v "^#" | grep -v "^$" user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* /(php-fpm-status|ping) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; include fastcgi_params; allow 127.0.0.1; ##注意这里 先应许本地访问再拒绝其他地址访问 deny all; access_log off; } } }
4、复制状态信息页面到网站根目录
[root@centos7 ~]# cp /usr/share/fpm/status.html /usr/share/nginx/html/
5、开启nginx服务
[root@centos7 ~]# systemctl start nginx
6、在agent 端,设置用户参数
1、查询 curl 192.168.30.7/php-fpm-status
2、设置
[root@centos7 ~]# cd /etc/zabbix/zabbix_agentd.d/ [root@centos7 ~]# vim php_status.conf UserParameter=php-fpm.stats[*],curl -s http://127.0.0.1/php-fpm-status | awk '/^$1/{print $$NF}'
分析:设置用户参数为php-fpm.stats[*],1 为 第 一 个 参 数 ; 1为第一个参数;1为第一个参数;$NF为awk中的参数,倒数第一列
3、重启服务
[root@centos7 ~]# systemctl restart zabbix-agent
4、在zabbix-server 端,查询使用这个用户参数的key
[root@centos7 ~]# zabbix_get -s 192.168.30.7 -p 10050 -k "php-fpm.stats[idle]" [root@centos7 ~]# zabbix_get -s 192.168.30.7 -p 10050 -k "php-fpm.stats[active]" [root@centos7 ~]# zabbix_get -s 192.168.30.7 -p 10050 -k "php-fpm.stats[max active]"
5、创建一个模板,在模板上创建4个item监控项,使用定义的用户参数
1、创建一个模板
2、在模板上配置 items 监控项,使用刚定义的用户参数
php-fpm.stats[total processes] ## total processes项是状态里的一个值 自己选取
3、再clone克隆几个items监控项
php-fpm.stats[accepted conn] ## accepted conn项是状态里的一个值 自己选取
php-fpm.stats[active processes]
php-fpm.stats[max active processes]
6、host主机链接模板
7、查看graph 图形
1、php-fpm total processes
2、php-fpm active processes
3、php-fpm max active processes
4、php-fpm idle processes
8、把模板导出,可以给别人使用
1、导出模板
2、自己定义用户参数的文件,也不要忘记导出
[root@centos7 ~]# /etc/zabbix/zabbix_agentd.d/php_status.conf