【2023】Prometheus-Blackbox_exporter使用

简介: 【2023】Prometheus-Blackbox_exporter使用

*.什么是black_exporter

Black_exporter是一种开源的Prometheus exporter,用于监控Blackbox probe的状态。

它的作用是在Prometheus中收集有关Blackbox probe的性能指标,并将其转换为Prometheus可读的格式。

这个工具可以用于监控网络服务的可用性和性能,例如HTTP、TCP和ICMP。它还支持动态配置,以便在运行时添加或删除监控目标。


1.下载及安装blackbox_exporter

  • 下载安装包
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.23.0/blackbox_exporter-0.23.0.linux-amd64.tar.gz
  • 将压缩包解压至/data目录下
mkdir /data
tar xf blackbox_exporter-0.23.0.linux-amd64.tar.gz -C /data/
cd /data
ln -s blackbox_exporter-0.23.0.linux-amd64/ blackbox_exporter

为blackbox_exporter创建启动文件

  vi /usr/lib/systemd/system/blackbox_exporter.service 
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/data/blackbox_exporter/blackbox_exporter \
          --config.file=/data/blackbox_exporter/blackbox.yml \
          --web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload 
systemctl start blackbox_exporter.service 
systemctl enable blackbox_exporter.service 

看到这个页面说明启动成功:通过IP:端口访问

fbfe2e49fe9343e2a5da81c00c81744e.png

2.修改配置文件设置监控内容

  • 安装完成后会有默认配置文件模板,分别有http探测、tcp探测、grpc探测、ssh探测、irc探测和icmp探测等内容。
  • 使用时可根据具体情况选择合适探测方式
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

2.1.使用http方式作为探测

vim blackbox.yml
  • 以下配置含义为:定义了一个名为http的http检测模块,超时时间为10s,探针验证的HTTP响应状态代码的为空数组,默认是200-299 。该探针使用的HTTP方法为GET,insecure_skip_verify: false 表示该探针不允许跳过TLS证书验证
modules:
  http:
    prober: http
    timeout: 10s
    http:
      valid_status_codes: []
      method: GET
      tls_config:
        insecure_skip_verify: false
systemctl restart blackbox_exporter

3.与prometheus集成

  • 修改prometheus配置文件
  vim prometheus.yml
  - job_name: "blackbox"
    metrics_path: /probe
    params:
    # 模块名需要与prober: http一致
      module: [http]
    static_configs:
    # 需要探测的域名
      - targets:
        - www.baidu.com
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.10.3:9115
systemctl restart prometheus
  • relabel_configs内容为:

1.将所有含有 address 标签的项目重新标记为 __param_target

2.将所有含有 __param_target 标签的项目重新标记为 instance

3.将所有 address 标签替换为 blackbox_exporter IP:9115

4.导入blackbox仪表盘进行观测

  • 怎么导入就不说了,请看我其他prometheus系列文章
  • 导入的仪表盘ID为7587
  • 仪表盘内容:

e19d7afaeac14922a457436e8b46b052.png更多内容请参考官方示例

目录
相关文章
Prometheus 整合 AlertManager
Alertmanager 主要用于接收 Prometheus 发送的告警信息,它很容易做到告警信息的去重,降噪,分组,策略路由,是一款前卫的告警通知系统。它支持丰富的告警通知渠道,可以将告警信息转发到邮箱、企业微信、钉钉等。这一节讲解利用AlertManager,把接受到的告警信息,转发到邮箱。
2084 0
|
7月前
|
存储 Prometheus 监控
【Prometheus】什么是prometheus?prometheus简介
【Prometheus】什么是prometheus?prometheus简介
57 0
|
5月前
|
Prometheus 监控 Cloud Native
Prometheus
Prometheus 是一款开源的监控和报警工具,可以用于监控各种类型的组件,例如应用程序、数据库、网络设备等等。它通过收集和处理指标来提供有关系统状态的实时和历史视图,并通过报警机制来通知管理员当系统出现异常时。
65 1
|
6月前
|
Prometheus 监控 Cloud Native
Prometheus的使用总结
Prometheus的使用总结
85 0
|
7月前
|
存储 Prometheus 监控
今天聊聊Prometheus
今天聊聊Prometheus
40 0
|
9月前
|
Prometheus Kubernetes Cloud Native
k8s安装prometheus
##### 安装 在目标集群上,执行如下命令: ```shell kubectl apply -f https://github.com/512team/dhorse/raw/main/conf/kubernetes-prometheus.yml ``` ##### 使用 1.在浏览器访问地址:http://master_ip:30000,如下图所示: 2.查看k8s自带的指标数据,如下图所示:
k8s安装prometheus
|
10月前
|
Prometheus Cloud Native NoSQL
【2023】Prometheus-Prometheus与Alertmanager配置详解
【2023】Prometheus-Prometheus与Alertmanager配置详解
480 0
【2023】Prometheus-Prometheus与Alertmanager配置详解
|
存储 Prometheus 监控
Prometheus的使用
Prometheus的使用
133 0
|
存储 Prometheus 监控
Exporter + Prometheus + Grafana进行监控
Exporter + Prometheus + Grafana进行监控
304 0
Exporter + Prometheus + Grafana进行监控
|
Prometheus 监控 Cloud Native
实战Prometheus-blackbox_exporter
Prometheus-blackbox_exporter