nginx prometheus exporter

nginx prometheus exporter

六月 03, 2021

新项目上线需要完善监控,除了系统部分使用node exporter,中间件使用了以下exporter
kafka exporter
redis exporter
mysql exporter
nginx prometheus exporter
mesos exporter

Nginx监控第一次做,网上查到的数据源使用prometheus监控Nginx的又比较少,多少还有点小坑,在此记录下~

拿包

1
$ wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.9.0/nginx-prometheus-exporter_0.9.0_linux_amd64.tar.gz

配置Nginx stub_status (nginx提供了stub_status模块,我们可以基于此进行监控)

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat /data/apps/config/nginx/conf.d/nginx_status.conf
server {
listen 8080;
access_log off;
server_name localhost;

location /nginx_status {
stub_status on;
access_log off;
allow 192.X.X.6;
deny all;
}
}

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
nginx_exporter$ ls
CHANGELOG.md LICENSE nginx_exporter_start.sh nginx-prometheus-exporter README.md

nginx_exporter$ cat nginx_exporter_start.sh
nohup ./nginx-prometheus-exporter -nginx.scrape-uri http://192.X.X.6:8080/nginx_status > /dev/null 2>&1 &
nginx_exporter$ ps -ef |grep exporter
ease 591 1 0 Apr28 ? 00:13:22 /usr/sbin/node_exporter --web.listen-address=0.0.0.0:9100 --collector.textfile.directory=/data/apps/data/promethous/
ease 13656 1 0 May10 ? 00:00:28 /data/apps/opt/consul_exporter/consul_exporter
ease 28649 1 0 15:35 pts/2 00:00:00 ./nginx-prometheus-exporter -nginx.scrape-uri http://192.X.X.6:8080/nginx_status

nginx_exporter$ curl 192.X.X.6:9113
<!DOCTYPE html>
<title>NGINX Exporter</title>
<h1>NGINX Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
```
metrics,获取到指标不是很多

$ curl http://192.X.X.6:9113/metrics

![](/img/nginx1.png)


从grafana找适合的模板导入dashboard
![](/img/nginx2.png)
![](/img/nginx3.png)


小坑:查到说 nginx-prometheus-exporter 只支持8080,一开始8080确实被监听了,但是是被业务console所占用。有机会再测试下换成8081会怎么样😋