当前位置: 首页 > 工具软件 > BlackBox > 使用案例 >

blackbox_exporter部署

尚棋
2023-12-01

简单介绍

blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。


环境

系统版本
CentOS7.6.1810 (Core)
CPU/内存4核、8G
blackbox_exporter0.22.0

软件包下载

CSDN

blackbox_exporter

官网

官网

下载这个 blackbox_exporter-0.22.0.linux-amd64.tar.gz

部署

解压

[root@A bag]# tar xf blackbox_exporter-0.22.0.linux-amd64.tar.gz
[root@A bag]# mv blackbox_exporter-0.22.0.linux-amd64 ../blackbox_exporter
[root@A bag]# useradd -M -s /sbin/nologin prometheus
[root@A bag]# chown -R prometheus:prometheus /data/blackbox_exporter

blackbox.yml

/data/blackbox_exporter/blackbox.yml

modules:
  http_2xx:
    prober: http
  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.service

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

启动

systemctl daemon-reload
systemctl enable blackbox_exporter --now
systemctl status blackbox_exporter
systemctl stop blackbox_exporter

Grafana监控配置

ID: 7362

prometheus.yml修改

参考

scrape_configs:
  - job_name: 'tcp_port_status'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
    - targets: ['192.168.1.10:3306','192.168.1.20:3307','192.168.1.30:3308']
      labels:
        instance: '192.168.1.10'
        tags: '自定义名字'
    - targets: ['192.168.1.40:2222']
      labels:
        instance: '192.168.1.40'
        tags: '自定义名字'
      relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 192.168.1.10:9115
      
  - job_name: 'web_port_status'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
    - targets: ['192.168.1.10:8080']
      labels:
        instance: '192.168.1.10'
        tags: '自定义名字'
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 192.168.1.10:9115

prometheus监控&插件方案

prometheus部署

总结

以上是centos上边部署blackbox_exporter监控端口的方法,有问题联系博主,后续也有其他插件

 类似资料: