Prometheus+Grafana+nginx-prometheus-exporter 监控 Nginx
Prometheus Grafana DevOps About 1,987 words下载 nginx-prometheus-exporter
https://github.com/nginxinc/nginx-prometheus-exporter/releases
前提
Nginx
需加载--with-http_stub_status_module
模块。
配置 metrics 端口
server {
listen 81;
location /metrics {
stub_status on;
}
}
访问数据采集端口
curl localhost:81/metrics
输出:
Active connections: 2
server accepts handled requests
2 2 16
Reading: 0 Writing: 1 Waiting: 1
备注
docker
启动时记得暴露metrics
端口给宿主机。
docker run -d \
--name=nginx \
-p 80:80 -p 81:81 \
-v $PWD/conf.d:/etc/nginx/conf.d \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx:1.20.2
后台启动
注意与其他exporter
命令行参数两个横杠--
不同,Nginx
官方开源的exporter
使用的是单横杠-
。
-web.listen-address
:指定Prometheus
抓取metrics
数据的端口。
-nginx.scrape-uri
:指定Nginx
暴露的stub_status
地址。
nohup /root/exporter/nginx-prometheus-exporter_0.10.0/nginx-prometheus-exporter \
-web.listen-address=:9113 \
-nginx.scrape-uri=http://127.0.0.1:81/metrics \
> nginx-prometheus-exporter.out 2>&1 &
开机启动
编辑
vim /etc/systemd/system/nginx-prometheus-exporter.service
内容:ExecStart
需要修改为nginx-prometheus-exporter
二进制文件的绝对路径
[Unit]
Description=nginx-prometheus-exporter
Documentation=https://github.com/nginxinc/nginx-prometheus-exporter
After=network.target
[Service]
Type=simple
User=root
ExecStart= /root/exporter/nginx-prometheus-exporter_0.10.0/nginx-prometheus-exporter \
-web.listen-address=:9113 \
-nginx.scrape-uri=http://127.0.0.1:81/metrics
Restart=on-failure
[Install]
WantedBy=multi-user.target
设为开机启动
sudo systemctl enable nginx-prometheus-exporter.service
启动nginx-prometheus-exporter
sudo systemctl start nginx-prometheus-exporter.service
nginx-prometheus-exporter 默认端口
修改 Prometheus 配置
scrape_configs
下新增job_name
为nginx
(名称随意)
- job_name: 'nginx'
static_configs:
- targets: ['192.168.0.100:9113']
重启 Prometheus
重启后可查看nginx-prometheus-exporter
是否上线。
Grafana Dashboard
NGINX exporter: https://grafana.com/grafana/dashboards/12708
开源地址
Views: 5,018 · Posted: 2022-02-26
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...