一:安装插件
1.1 查看nginx已启用tub_status模块
nginx -V 2>&1 | grep -o with-http_stub_status_module 如果在终端输出with-http_stub_status_module,说明nginx已启用tub_status模块
在nginx 的配置文件添加如下配置
location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
1.2 下载插件nginx-prometheus-exporte 插件
nginx-prometheus-exporter用于把nginx的性能指标(stub_status)转化为prometheus可用的数据格式
在https://github.com/nginxinc/nginx-prometheus-exporter/releases下载nginx-prometheus-exporter_1.1.0_linux_amd64.tar.gz 安装包,并上传到nginx服务器/usr/local 目录下
1.3 安装nginx-prometheus-exporte
[root@rancher local]# mkdir nginx_exporter
[root@rancher local]# mv nginx-prometheus-exporter_1.1.0_linux_amd64.tar.gz ./nginx_exporter/
[root@rancher local]# cd nginx_exporter/
[root@rancher nginx_exporter]# tar -xvf nginx-prometheus-exporter_1.1.0_linux_amd64.tar.gz
[root@rancher local]# vim /usr/lib/systemd/system/nginx_exporter.service
[Unit] Description=nginx_exporter After=network.target [Service] Restart=on-failure ExecStart=/usr/local/nginx_exporter/nginx-prometheus-exporter -nginx.scrape-uri http://10.12.121.198:7006/nginx_status [Install] WantedBy=multi-user.target
[root@rancher local]# systemctl restart nginx_exporter.service
[root@rancher local]# systemctl enable nginx_exporter.service
输入流量访问http://10.12.121.198:9113/metrics
1.4 prometheus配置
[root@rancher prometheus]# vim /data/prometheus/prometheus.yml
###nginx - job_name: 'nginx_status' metrics_path: '/metrics' scrape_interval: 5s static_configs: - targets: ["10.12.121.198:9113"] relabel_configs: - source_labels: [__address__] regex: "([^:]+):\\d+" target_label: instance
[root@rancher prometheus]# systemctl reload prometheus.service
登陆prometheus 后台查看nginx
Targets
标签:status,exporter,grafana,nginx,prometheus,rancher,root From: https://www.cnblogs.com/QIzhu/p/18186694