prometheus使用blackbox监控TCP

2022-10-27 14:42:28 浏览数 (1)

下载安装blackbox

代码语言:javascript复制
https://github.com/prometheus/blackbox_exporter/releases

配置prometheus.yml

代码语言:javascript复制
  - job_name: 'black_exporter_tcp'
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets:
        - 172.16.20.213:12800
        labels:
          alias: skywalking
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.16.20.150:9115

创建启动脚本

代码语言:javascript复制
vim /usr/lib/systemd/system/blackbox_exporter.service

[Unit]
Documentation=https://github.com/prometheus/blackbox_exporter
After=network.target


[Service]
User=root
ExecStart=/usr/local/bin/blackbox_exporter --config.file=/etc/prometheus/blackbox.yml
Restart=on-failure
RestartSec=5s


[Install]
WantedBy=multi-user.target

添加告警通知

代码语言:javascript复制
vim /etc/prometheus/rules/blackbox.yml

groups:
- name: blackbox_exporter_tcp
  rules:
    - alert: BlackboxEndpointDown
      expr: probe_success == 0
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: "BlackboxEndpoint {{ $labels.instance }} down"

重启prometheus

0 人点赞