grafana-prometheus-php-fpm
公司新项目需要增加PHP服务器的监控,所以自己百度搞了一套,整理一下,记录下来,利用php-fpm自带的状态页实现。
nginx
需要配置nginx.conf内容如下
server {
listen 9010;
location ~ ^/(status|ping)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
通过NGINX去定向解析php-fpm的状态页。
PHP-FPM
找到php-fpm所在的配置文件www.conf 添加内容如下
pm.status_path = /status
ping.path = /ping
重启php-fpm
systemctl restart php-fpm
PHP-FPM-EXPORTER
下载与prometheus搭配使用的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/prometheus
mv ./php-fpm-exporter.linux.amd64 /usr/local/prometheus
chown +x /usr/local/prometheus/php-fpm-exporter.linux.amd64
- 启动
nohup ./php-fpm-exporter.linux.amd64 --addr 127.0.0.1:9190 --endpoint http://127.0.0.1:9010/stauts > /var/logs/proemthues.log 2>&1 &
配置promethues
找到启动promethues的配置文件promethues.yml
修改内容如下
- job_name: 'PHP-FPM'
static_configs:
- targets:
- 127.0.0.1:9190
重启promethues
systemctl restart promethues.server
- 查看配置的状态
State Up OK
grafana配置图表
推荐图表地址
https://grafana.com/dashboards/3901php-fpm图表
直接import 导入 3901
完成!
友情链接:
- grafana图表地址:https://grafana.com/grafana/dashboards?dataSource=prometheus
- promethues扩展地址:https://prometheus.io/download/