1.进入默认php配置文件:/etc/php/7.3/fpm/php-fpm.conf 添加:pm.status_path = /fpm_status
echo "pm.status_path = /fpm_status" >>/etc/php/7.3/fpm/php-fpm.conf
2.在nginx配置文件下面添加fpm-status location配置:/etc/nginx/conf.d/nginx-php.conf
location ~ ^/(fpm_status|health)$ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
systemctl restart php7.3-fpm
systemctl reload nginx
测试一下:curl http://localhost:9090/fpm_status 有数据就ok
安装这个文件: php-fpm-exporter.linux.amd64 (官网地址:https://github.com/bakins/php-fpm-exporter/releases)
安装好了 :
mkdir /usr/local/php-fpm-exporter/
scp [email protected]:~/php-fpm-exporter /usr/local/php-fpm-exporter/
cd /usr/local/php-fpm-exporter/
chmod +x php-fpm-exporter
nohup ./php-fpm-exporter --addr="172.0.100.49:9190" --endpoint="http://172.0.100.49:9090/fpm_status" >nohup.out 2>&1 &
netstat -ntpl |grep
测试:curl 172.0.100.49:9190/metrics(也可以不用测试)
nohup /usr/local/php-fpm-exporter/php-fpm-exporter --addr="`ip a|grep global|awk -F'[ ]+|/' '{print $3}'`:9190" --endpoint="http://`ip a|grep global|awk -F'[ ]+|/' '{print \$3}'`:9090/fpm_status" >/usr/local/php-fpm-exporter/nohup.out 2>&1 &
server {
listen 9090 backlog=8192;
server_name 172.0.100.33;
root /data/qcnft_php/public;
access_log /data/log/nginx/qcsc_access.log log_json;
error_log /data/log/nginx/qcsc_error.log;
keepalive_timeout 60s;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
location = /nginx_status {
stub_status on;
access_log off;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 150;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~ ^/(fpm_status|health)$ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
标签:status,exporter,log,fpm,Prometheus,php,fastcgi
From: https://www.cnblogs.com/mchbook/p/17397837.html