• 【云原生 | Kubernetes 系列】---Prometheus Blackbox_exporter监控


    Prometheus Blackbox_exporter监控

    blackbox_exporter是Prometheus官方提供的一个exporter,可以通过Http,Https,Dns,Tcp和ICMP对被监控节点进行数据采集.

    在Prometheus中配置监控项,将监控项指向blackbox.blackbox根据监控项再去监控目标

    1. 安装blackbox_exporter

    # mkdir /apps
    # cd /apps
    # wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.22.0/blackbox_exporter-0.22.0.linux-amd64.tar.gz
    # tar xf blackbox_exporter-0.22.0.linux-amd64.tar.gz
    # ln -sf /apps/blackbox_exporter-0.22.0.linux-amd64/blackbox_exporter /usr/bin/
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2. 配置Service文件

    /etc/systemd/system/blackbox_exporter.service

    [Unit]
    Description=Prometheus blackbox_exporter
    After=network.target
    
    [Service]
    ExecStart=/usr/bin/blackbox_exporter --config.file=/apps/blackbox_exporter-0.22.0.linux-amd64/blackbox.yml --web.listen-address=:9115
    
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    启动服务后在9115启动监听

    # systemctl enable --now blackbox_exporter
    Created symlink /etc/systemd/system/multi-user.target.wants/blackbox_exporter.service → /etc/systemd/system/blackbox_exporter.service.
    # ss -ntl|grep 9115
    LISTEN  0       4096                    *:9115                 *:* 
    
    • 1
    • 2
    • 3
    • 4

    此时prometheus还没有配置,所以target里是空的

    请添加图片描述

    3. 配置Prometheus

    3.1 监控url

    主要用来监控一些页面状态和SSL证书有效期.

      - job_name: 'http_status'
        metrics_path: /probe
        params:
          module: [http_2xx]
        static_configs:
          - targets: ['https://www.baidu.com', 'http://192.168.31.201:9090']
            labels:
              instance: http_status
              group: web
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: url
          - target_label: __address__
            replacement: 192.168.31.122:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    重启Prometheus服务后,访问blackbox:9115

    请添加图片描述

    同时在prometheus里也看到了相关的监控项数据

    请添加图片描述

    3.2 监控ICMP

    主要用来监控一些网关,vip等ip地址

      - job_name: 'ping_status'
        metrics_path: /probe
        params:
          module: [icmp]
        static_configs:
          - targets: ['192.168.31.101',"192.168.31.114"]
            labels:
              instance: 'ping_status'
              group: 'icmp'
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: ip
          - target_label: __address__
            replacement: 192.168.31.122:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    重启prometheus,获得了ping_status的监控项

    请添加图片描述

    3.3 监控端口

    主要用来监视无法直接通过http返回2xx监控的那些服务端口

      - job_name: 'port_status'
        metrics_path: /probe
        params:
          module: [tcp_connect]
        static_configs:
          - targets: ['192.168.31.101:6443', '192.168.31.201:3000','192.168.31.121:22','192.168.31.126:3306']
            labels:
              instance: 'port_status'
              group: 'port'
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: ip
          - target_label: __address__
            replacement: 192.168.31.122:9115
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    重启prometheus后

    请添加图片描述

    4. Grafana 导入

    9965

    请添加图片描述

  • 相关阅读:
    数字云栖,与您共享极致计算与创新进化的科技盛宴
    Linux
    腾讯大数据 x StarRocks|构建新一代实时湖仓
    jar包,引入依赖
    ByteV数字孪生实际应用案例-智慧矿山篇
    OWASP-TOP10漏洞-注入漏洞
    MySQL集群:双主模式
    java生成excel,uniapp微信小程序接收excel并打开
    如何训练聊天机器人面对复杂的语言环境和需求?
    Pytorch+Python实现人体关键点检测
  • 原文地址:https://blog.csdn.net/qq_29974229/article/details/126703972