zabbix用户自定义参数监控 php-fpm 服务的状态及导出模板和自定义参数

本文介绍如何通过Zabbix监控PHP-FPM服务状态,包括配置php-fpm、nginx、zabbix-agent,以及创建监控项和图形展示。适用于希望精细化监控PHP应用服务器状态的运维人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用用户自定义参数监控 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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JRqk8Amd-1594988051703)(C:/Users/Administrator/Desktop/%E7%9B%91%E6%8E%A7%E5%B9%B3%E5%8F%B0%E9%83%A8%E7%BD%B2%E5%8F%8A%E5%BA%94%E7%94%A8/assets/1216496-20171226172030088-1020205629.png)]

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 

----------------------------当你发现自己突然嫉妒起其他人时,就请安静下来学习吧!--------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大鹅i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值