prometheus监控php

利用php-fpm-exporter对php-fpm进行监控
1、php-fpm开启status接口
2、nginx代理php-fpm接口
3、使用php-fpm-exporter暴露指标给Prometheus
4、granfna展示

一、 php-fpm 开启status接口
需要提前安装好php,和nginx 环境 找到php配置文件,修改配置,开启status vim /usr/local/php/etc/php-fpm.conf

...
pm.status_path = /status
ping.path = /ping
...

2、 配置nginx

server {
        listen 9010;

        allow 127.0.0.1;
        deny all;
        location ~ ^/(status|ping)$ {
            include fastcgi.conf;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        }
}
~            

3 检查status是否可以访问

[root@vm-hc-mysteelRC-web-php01 conf.d]# curl  http://127.0.0.1:9010/status
pool:                 www
process manager:      static
start time:           23/Aug/2022:19:50:19 +0800
start since:          983
accepted conn:        2
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       31
active processes:     1
total processes:      32
max active processes: 1
max children reached: 0
slow requests:        0

4 使用php-fpm-exporter暴露指标

wget https://github.com/bakins/php-fpm-exporter/releases/download/v0.6.1/php-fpm-exporter.linux.amd64
mkdir -p /usr/local/exporter/php-fpm/
mv php-fpm-exporter.linux.amd64 /usr/local/exporter/php-fpm/php-fpm-exporter
nohup /usr/local/exporter/php-fpm/php-fpm-exporter --addr 0.0.0.0:9190 --endpoint http://127.0.0.1:9010/status &

nginx 和 php-fpm 配置 错误 connect () failed (111: Connection refused) while connecting to upstream connec… 错误502
若 fpm 配置文件中配置如下:

listen = 127.0.0.1:9000

则对应的 nginx.conf 中的配置应为:

fastcgi_pass   127.0.0.1:9000;

此时开启 9000 端口监听,不会生成 sock 文件

若 fpm 中的配置为使用 Unix 套接字,如下:

listen = /var/run/php-fpm/php-fpm.sock

则对应 nginx.conf 中的配置应为:

fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock

使用php-fpm-exporter暴露指标
1、下载php-fpm-exporter,并启动

wget https://github.com/bakins/php-fpm-exporter/releases/download/v0.6.1/php-fpm-exporter.linux.amd64
mkdir -p /usr/local/exporter/php-fpm/
mv php-fpm-exporter.linux.amd64 /usr/local/exporter/php-fpm/php-fpm-exporter
nohup /usr/local/exporter/php-fpm/php-fpm-exporter --addr 0.0.0.0:9190 --endpoint http://127.0.0.1:9010/status &

2、检查metrics是否可以访问

[root@vm-hc-mysteelRC-web-php01 conf.d]# curl 127.0.0.1:9190/metrics
# HELP phpfpm_accepted_connections_total Total number of accepted connections
# TYPE phpfpm_accepted_connections_total counter
phpfpm_accepted_connections_total 5
# HELP phpfpm_active_max_processes Maximum active process count
# TYPE phpfpm_active_max_processes counter
phpfpm_active_max_processes 1
# HELP phpfpm_listen_queue_connections Number of connections that have been initiated but not yet accepted
# TYPE phpfpm_listen_queue_connections gauge
phpfpm_listen_queue_connections 0
# HELP phpfpm_listen_queue_length_connections The length of the socket queue, dictating maximum number of pending connections
# TYPE phpfpm_listen_queue_length_connections gauge
phpfpm_listen_queue_length_connections 0
# HELP phpfpm_listen_queue_max_connections Max number of connections the listen queue has reached since FPM start
# TYPE phpfpm_listen_queue_max_connections counter
phpfpm_listen_queue_max_connections 0
# HELP phpfpm_max_children_reached_total Number of times the process limit has been reached
# TYPE phpfpm_max_children_reached_total counter
phpfpm_max_children_reached_total 0
# HELP phpfpm_processes_total process count
# TYPE phpfpm_processes_total gauge
phpfpm_processes_total{state="active"} 1
phpfpm_processes_total{state="idle"} 31
# HELP phpfpm_scrape_failures_total Number of errors while scraping php_fpm
# TYPE phpfpm_scrape_failures_total counter
phpfpm_scrape_failures_total 0
# HELP phpfpm_slow_requests_total Number of requests that exceed request_slowlog_timeout
# TYPE phpfpm_slow_requests_total counter
phpfpm_slow_requests_total 0
# HELP phpfpm_up able to contact php-fpm
# TYPE phpfpm_up gauge
phpfpm_up 1

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值