栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

prometheus监控传统环境监控(二)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

prometheus监控传统环境监控(二)

prometheus监控nginx

环境:

        组件nginx-prometheus-exporter部署位置:192.168.0.39

        nginx服务器:172.30.0.10

通过组件nginx-prometheus-exporter进行监控

nginx需要安装有with-http_stub_status_module模块,一般高版本的nginx会自带这个模块

检查

# nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_stub_status_module

nginx增加配置

创建一个server,监听38888端口,开启监控,只允许192.168.0.39访问

server {
        listen  38888;
        location /nginx_status {
            stub_status on;
            allow 192.168.0.39;  #only allow requests from localhost
            deny all;   #deny all other hosts
        }
    }

测试一下

172.30.0.10就是刚刚那台nginx主机

# curl http://172.30.0.10:38868/nginx_status

Active connections: 12189 
server accepts handled requests
 195544839 195544839 1147258694 
Reading: 0 Writing: 63 Waiting: 12018

创建启动监控组件

需要指定被监控主机(我这里没试过能不能添加多个被监控主机,有测试过的小伙伴可以留言)

我启动了多个组件

端口:9117 自定义的

docker run -d 
--name nginx_exporter_qalb_10 
-m 1g 
--restart=always 
--restart=on-failure:5 
-p 9117:9113 
nginx/nginx-prometheus-exporter:0.10.0 
-nginx.scrape-uri http://172.30.0.10:38888/nginx_status

prometheus集成nginx-prometheus-exporter组件

prometheus.yml

添加

# nginx
  - job_name: nginx-qalb-10
    static_configs:
      - targets: ['192.168.0.10:9117']
        labels:
          instance: nginx-qalb-10

有多个组件就再加一个,注意端口别冲突
  - job_name: nginx-qalb-11
    static_configs:
      - targets: ['192.168.0.10:9118']
        labels:
          instance: nginx-qalb-11

重启prometheus容器

添加告警规则

nginx_export-alert-rules.yaml

groups:
    - name: nginx状态-监控告警
      rules:
      - alert: nginx状态
        expr: nginx_up == 0
        for: 1s
        labels:
          serverity: warning
          status: 非常严重
        annotations:
          summary: "{{$labels.instance}}:nginx服务停止"
          description: "nginx服务down"

重启prometheus容器生效

上一篇:基础环境搭建

prometheus监控传统环境监控(一)_我的喵叫初六的博客-CSDN博客

下一篇:URL监控

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/865553.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号