一、PHP主机配置:
1.修改nginx配置:
server {
listen 8080;
server_name localhost;
root /home/work/webserver/document/tsqianjia/apps/web/public;
location ~ ^/Nginxstatus/ {
stub_status on;
access_log off;
}
location ~ ^/(fpm_status|health)$ {
#fastcgi_pass 192.168.31.34:9000;
fastcgi_pass unix:/home/work/webserver/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
平滑重启:
./nginx -t
./nginx -s reload
2.修改php-fpm.conf配置:
pm.status_path = /fpm_status;
默认情况下为pm.status_path = /status,当然也可以改成其他。
平滑重启:
service php-fpm reload
3.检查是否起作用:
[root@qjcsc69n19 sbin]# curl http://127.0.0.1:8080/fpm_status
pool: www
process manager: dynamic
start time: 29/Oct/2020:14:12:55 +0800
start since: 145
accepted conn: 144
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 5
active processes: 1
total processes: 6
max active processes: 5
max children reached: 0
slow requests: 0
php-fpm 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,缓慢请求的数量
4.PHP主机安装php-fpm-exporter:
4.1下载:
地址:https://github.com/bakins/php-fpm-exporter/releases
4.2 安装:
mkdir /usr/share/php-fpm-exporter
mv php-fpm-exporter.linux.amd64 /usr/share/php-fpm-exporter/php-fpm-exporter
chmod +x /usr/share/php-fpm-exporter/php-fpm-exporter/php-fpm-exporter
4.3启动:
cd /usr/share/php-fpm-exporter/php-fpm-exporter/
nohup ./php-fpm-exporter --addr 0.0.0.0:9190 --endpoint http://127.0.0.1:8080/fpm_status >> php-fpm-exporter.log 2>&1 &
二、监控主机配置:
sudo vim prometheus.yml
global: # 全局设置,可以被覆盖
scrape_interval: 15s # 默认值为 15s,用于设置每次数据收集的间隔
evaluation_interval: 15s
external_labels: # 所有时间序列和警告与外部通信时用的外部标签
# Alertmanager配置
alerting:
alertmanagers:
- static_configs:
- targets:
- 172.18.0.1:9093 # 设定alertmanager和prometheus交互的接口,即alertmanager监听的ip地址和端口
rule_files:
- "/etc/prometheus/rules/*.yml"
scrape_configs:
- job_name: php-fpm
metrics_path: "/metrics"
file_sd_configs:
- files:
- /etc/prometheus/conf.d/php-fpm.json
sudo vim conf.d/php-fpm.json
[
{
"targets": ["39.107.59.230:9190"],
"labels": {
"instance": "erp_pred_php-fpm"
}
}
]
然后重启
sudo docker restart prometheus
或者平滑启动:
curl -X POST http://127.0.0.1:9090/-/reload
三、Grafana端
dashboards.id 推荐3901