blackbox-exporter使用

    blackbox-exporter是Prometheus 官方提供的 exporter 之一,主要提供http、dns、tcp、icmp 的监控数据采集

一、部署

    通过docker-compose部署

version: '2'

services:
  blackbox_exporter:
    container_name: blackbox_exporter
    image: xxxx/blackbox-exporter
    volumes:
      - blackbox_exporter/config.yml:/etc/blackbox_exporter/config.yml
    ports:
      - 9115:9115

 

modules:
  http_2xx:
    prober: http
  http_header_2xx:
    prober: http
    http:
      method: GET
      headers:
        Content-Type: application/json#可添加header
   
  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
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
  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
config.yml

 

prometheus配置

  - job_name: 'telnet'
    scrape_interval: 45s
    metrics_path: /probe
    params:
      module: [tcp_connect]  # Look for a HTTP 200 response.
    file_sd_configs:
    - files:
      - ./blackbox/*.yml
      refresh_interval: 10s
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox_exporter:9115  

  - job_name: 'ping'
    scrape_interval: 10s
    metrics_path: /probe
    params:
      module: [icmp]  # Look for a HTTP 200 response.
    file_sd_configs:
    - files:
      - ./ping/*.yaml
      refresh_interval: 10s
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target,idc,isp]
      separator: _
      target_label: instance
    - target_label: __address__
      replacement: blackbox_exporter:9115


  - job_name: 'http_status'
    scrape_interval: 45s
    metrics_path: /probe
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    file_sd_configs:
    - files:
      - ./http_status/*.yml
      refresh_interval: 10s
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox_exporter:9115  


  - job_name: 'http_status_header'
    scrape_interval: 45s
    metrics_path: /probe
    params:
      module: [http_header_2xx]  # Look for a HTTP 200 response.
    file_sd_configs:
    - files:
      - ./http_status_header/*.yml
      refresh_interval: 10s
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox_exporter:9115

 

posted @ 2023-10-20 17:45  泉love水  阅读(645)  评论(0编辑  收藏  举报