Prometheus:Windows Server 2019 安装 blackbox_exporter 黑盒监控

Posted by: NOTEPAD 2023年1月18日 Leave a comment

blackbox_exporter是Prometheus 官方提供的 exporter

可以提供 http、dns、tcp、icmp 的监控数据采集

blackbox_exporter 地址:https://github.com/prometheus/blackbox_exporter

解压blackbox_exporter win安装包

使用nssm.exe注册成为系统服务

输入网址验证 blackbox_exporter 端口为9115

我们去 prometheus.yml 编写监控代码

HTTP 监控写法

  - job_name: 'HTTP_GET_ALL'  
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        - https://www.baidu.com
        - https://notepad.com.cn                
        labels:
          instance: 'HTTP_GET_ALL' 
          group: 'web'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 

TCP 监控写法

  - job_name: 'PORT_STATUS'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets: ['127.0.0.1:9090','127.0.0.1:3000']
        labels:
          instance: 'port_status'
          group: 'tcp'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115

ICMP 监控写法

- job_name: 'Node_Status'
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets: ['8.8.8.8']
        labels:
          instance: 'ENS172'
          group: 'node'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 127.0.0.1:9115