news 2026/11/5 16:36:23

Prometheus(普罗米修斯)----- Nginx监控

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Prometheus(普罗米修斯)----- Nginx监控

一、查看是否安装stub_status模块

1、查看www-nginx是否安装stub_status模块
#进入目录 cd /opt/nginx/www-nginx/sbin #查看是否安装 ./nginx -V 2>&1 | grep -o with-http_stub_status_module ##如果没安装重新安装编译 ./configure --prefix=/opt/nginx/www-nginx --with-http_stub_status_module make & make install ##启动 ./nginx ##查看是否配置 curl http://192.168.1.41:20080/stub_status
2、查看www2-nginx是否安装stub_status模块
#进入目录 cd /opt/nginx/www-nginx/sbin #查看是否安装 ./nginx -V 2>&1 | grep -o with-http_stub_status_module ##如果没安装重新安装编译 ./configure --prefix=/opt/nginx/www-nginx --with-http_stub_status_module make & make install ##启动 ./nginx ##查看是否配置 curl http://192.168.1.41:60080/stub_status

二、安装nginx_export

wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v1.3.0/nginx-prometheus-exporter_1.3.0_linux_amd64.tar.gz tar -zxvf nginx-prometheus-exporter_1.3.0_linux_amd64.tar.gz -C /portal/monitor/nginx-prometheus-exporter chown prometheus:prometheus -R /portal/monitor/

三、配置nginx的conf文件

server { listen 20080; listen [::]:20080; server_name localhost; error_page 404 403 500 502 503 504 /50x.html; location / { root html; index index.html index.htm; } location = /50x.html { root html; } location = /stub_status { # 具体路径可根据业务情况进行调整 stub_status on; access_log off; allow 192.168.1.41; deny all; } }

四、配置www-nginx的systemd

cd etc/systemd/system

vim www_nginx_exporter.service

[Unit] Description=www-nginx-prometheus-exporter After=network.target [Service] Type=simple User=prometheus Group=prometheus Restart=always ExecStart=/portal/monitor/nginx_exporter/nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.1.41:20080/stub_status -web.listen-address=:9113 [Install] WantedBy=multi-user.target

五、配置www2-nginx的systemd

cd etc/systemd/system

vim www2_nginx_exporter.service

[Unit] Description=www2-nginx-prometheus-exporter After=network.target [Service] Type=simple User=prometheus Group=prometheus Restart=always ExecStart=/portal/monitor/nginx_exporter/nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.1.41:60080/stub_status -web.listen-address=:9114 [Install] WantedBy=multi-user.target

systemctl daemon-reload

systemctl start www_nginx_exporter.service

systemctl enable www2_nginx_exporter.service

##访问地址www

http://192.168.1.41:9113/metrics

##访问地址www2

http://192.168.1.41:9114/metrics

六、配置prometheus

# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: - localhost:9193 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - "alert.yml" # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. scrape_interval: 15s static_configs: - targets: ["localhost:9090"] - job_name: "node-exporter" scrape_interval: 15s static_configs: - targets: ["192.168.1.41:9100"] labels: instance: 192.168.1.41服务器 - targets: ["192.168.1.42:9100"] labels: instance: 192.168.1.42服务器 - targets: ["192.168.1.43:9100"] labels: instance: 192.168.1.43服务器 - targets: ["192.168.1.44:9100"] labels: instance: 192.168.1.44服务器 ## 添加一下内容 - job_name: "www_nginx_exporter" static_configs: - targets: ["192.168.1.41:9113"] labels: instance: prod4-nginx服务器 - job_name: "www2_nginx_exporter" static_configs: - targets: ["192.168.1.41:9114"] labels: instance: prod6-nginx服务器

七、prometheus配置alert

groups: - name: Prometheus alert rules: # 对任何实例超过30s无法联系的情况发出警告 - alert: 服务告警 expr: up == 0 for: 30s labels: severity: critical annotations: instance: "{{ $labels.instance}}" description: "{{ $labels.job}} 服务已关闭" - name: Nginx rules: # 检查 nginx_exporter 端口 9113(适用于20080端口的nginx实例) - alert: WWWNginxDown expr: up{job="nginx_exporter", instance="192.168.1.41:9113"} == 0 for: 30s labels: severity: critical annotations: instances: "nginx异常,实例:{{ $labels.instance }}" description: "prod4 的 nginx 已关闭" # 检查 nginx_exporter 端口 9114(适用于60080端口的nginx实例) - alert: WWW2NginxDown expr: up{job="nginx_exporter", instance="192.168.1.41:9114"} == 0 for: 30s labels: severity: critical annotations: instances: "nginx异常,实例:{{ $labels.instance }}" description: "prod6 的 nginx 已关闭"

八、重载

curl -X POST http://192.168.1.41:9090/-/reload

九、查看是否监听到

http://192.168.1.41:9090/

十、Granfa导入模板

模板编号12708

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/10/5 1:25:14

VibeVoice Pro部署教程:Ampere架构GPU上4GB显存极限压测记录

VibeVoice Pro部署教程&#xff1a;Ampere架构GPU上4GB显存极限压测记录 1. 项目简介&#xff1a;重新定义实时语音生成 VibeVoice Pro 不仅仅是一款普通的文本转语音工具&#xff0c;它是专门为需要"低延迟"和"高吞吐"场景设计的实时音频生成引擎。与传…

作者头像 李华
网站建设 2026/10/5 1:26:14

跨平台设备驱动解决方案:实现苹果设备与多系统无缝连接

跨平台设备驱动解决方案&#xff1a;实现苹果设备与多系统无缝连接 【免费下载链接】Apple-Mobile-Drivers-Installer Powershell script to easily install Apple USB and Mobile Device Ethernet (USB Tethering) drivers on Windows! 项目地址: https://gitcode.com/gh_mi…

作者头像 李华
网站建设 2026/10/5 1:26:14

从理论到产品:Pi0模型在智能家居中的商业化应用案例

从理论到产品&#xff1a;Pi0模型在智能家居中的商业化应用案例 1. 引言 想象一下&#xff0c;清晨醒来&#xff0c;家里的机器人助手已经为你准备好了早餐&#xff0c;收拾好了房间&#xff0c;甚至把脏衣服都洗好晾好了。这听起来像是科幻电影里的场景&#xff0c;但现在&a…

作者头像 李华
网站建设 2026/10/5 1:29:41

实战应用:基于快马平台快速构建集成db9接口定义的串口调试助手

最近在做一个硬件联调项目&#xff0c;需要频繁和各类带DB9串口的设备打交道&#xff0c;比如PLC、读卡器、老式工控屏等等。每次都要翻手册查引脚定义&#xff0c;用各种串口调试工具来回切换&#xff0c;还得手动模拟控制信号&#xff0c;效率很低。于是我就想&#xff0c;能…

作者头像 李华