Prometheus-黑盒blackbox

安装

[ -d "/data/monitor" ] || mkdir /data/monitor -p
cd /data/monitor

wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
tar fx blackbox_exporter-0.24.0.linux-amd64.tar.gz
mv blackbox_exporter-0.24.0.linux-amd64 blackbox_exporter
cd blackbox_exporter

配置文件: blackbox.yml

modules:
  http_2xx:
    prober: http
    timeout: 15s  
    http:
      fail_if_not_ssl: true
      ip_protocol_fallback: false
      method: GET
      follow_redirects: false
      preferred_ip_protocol: ip4
      enable_http2: true
      tls_config:
        insecure_skip_verify: true
      valid_http_versions:
        - HTTP/1.1
        - HTTP/2.0
      valid_status_codes:
        - 200
        - 201
        - 204
        - 301
        - 302
        - 307
        - 400
        - 401
        - 403
        - 404
        - 405
  http_post_2xx:
    prober: http
    http:
      method: POST
  tcp_connect:
    prober: tcp
  pop3s_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^+OK"
      tls: true
      tls_config:
        insecure_skip_verify: false
  grpc:
    prober: grpc
    grpc:
      tls: true
      preferred_ip_protocol: "ip4"
  grpc_plain:
    prober: grpc
    grpc:
      tls: false
      service: "service1"
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
      - send: "SSH-2.0-blackbox-ssh-check"
  irc_banner:
    prober: tcp
    tcp:
      query_response:
      - send: "NICK prober"
      - send: "USER prober prober prober :prober"
      - expect: "PING :([^ ]+)"
        send: "PONG ${1}"
      - expect: "^:[^ ]+ 001"
  icmp:
    prober: icmp
  icmp_ttl5:
    prober: icmp
    timeout: 5s
    icmp:
      ttl: 5

方式一: 终端方式

blackbox_exporter --config.file=blackbox.yml

方式二: systemd 服务方式

cat > /usr/lib/systemd/system/blackbox_exporter.service << EOF
[Unit]
Description=blackbox_exporter
After=network.target 
[Service]
WorkingDirectory=/data/monitor/blackbox_exporter
ExecStart=blackbox_exporter          --config.file=blackbox.yml
[Install]
WantedBy=multi-user.target
EOF

方式三: supervisor 进程方式

cat > /etc/supervisor/conf.d/blackbox.conf 
[program:blackbox]
directory = /data/monitor/blackbox_exporter/
command = /data/monitor/blackbox_exporter/blackbox_exporter --config.file=/data/monitor/blackbox_exporter/blackbox.yml
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile = /data/monitor/logs/blackbox.log
EOF

参考配置格式

新建一个 http_<自定义的名字>.yml 的配置文件,格式复制,域名扔进去, 不加 https:// ,默认 http(如果没有强制 ssl, 则不会检查https)

检查配置,设置立即生效

cd /data/monitor/prometheus/
./promtool check config ./prometheus.yml
curl -XPOST 127.0.0.1:8090/-/reload

Last updated