Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker DevOps


Prometheus+Grafana+blackbox_exporter 监控 HTTP TCP PING ICMP

Prometheus Grafana DevOps 大约 3526 字

blackbox_exporter 下载地址

https://github.com/prometheus/blackbox_exporter/releases

后台启动

默认监听9115端口,是blackbox_exporter自带的Web页面。

nohup /root/exporter/blackbox_exporter-0.19.0/blackbox_exporter \
--config.file="/root/exporter/blackbox_exporter-0.19.0/blackbox.yml" \
--web.listen-address=":9115" \
--log.level=debug \
> blackbox_exporter.out 2>&1 &

开机启动

编辑

vim /etc/systemd/system/blackbox_exporter.service

内容:ExecStart需要修改为blackbox_exporter二进制文件的绝对路径

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

[Service]
Type=simple
User=root
ExecStart= /root/exporter/blackbox_exporter-0.19.0/blackbox_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

设为开机启动

sudo systemctl enable blackbox_exporter.service

启动blackbox_exporter

sudo systemctl start blackbox_exporter.service

blackbox_exporter 默认端口

http://localhost:9115

修改 Prometheus 配置

prometheus.yml文件中修改。

  - job_name: 'blackbox_http_2xx' # 配置 GET 请求检测
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:         # 测试如下的请求是否可以访问的通
        - 127.0.0.1:8080
        - http://127.0.0.1:8080/test
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # blackbox-exporter 服务所在的机器和端口
  - job_name: 'blackbox_http_post_2xx' # 配置 POST 请求检测
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [http_post_2xx]
    static_configs:
      - targets:              # 测试如下的 POST 请求是否可以访问的通,该 POST 请求不带参数
        - http://127.0.0.1:8080/test2
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # blackbox-exporter 服务所在的机器和端口
  - job_name: 'blackbox_http_ping' # 检测是否可以ping通某些机器
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets:
        - 127.0.0.1
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # blackbox-exporter 服务所在的机器和端口
  - job_name: 'blackbox_tcp_connect' # 检测某些端口是否在线
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [tcp_connect]
    static_configs:
      - targets:
        - 127.0.0.1:8080 # Java 服务
        - 127.0.0.1:9090 # prometheus 服务
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # blackbox-exporter 服务所在的机器和端口

检查配置文件

promtool check config /etc/prometheus/prometheus.yml

Docker部署的Prometheus可使用:

docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

输出:

Checking /etc/prometheus/prometheus.yml
  SUCCESS: 0 rule files found

重启 Prometheus

重启后可查看blackbox_exporter是否上线。

http://localhost:9090/targets

Grafana Dashboard

Prometheus Blackbox Exporter:https://grafana.com/grafana/dashboards/7587

Blackbox Exporter Dashboard 20220107:https://grafana.com/grafana/dashboards/9965

开源地址

https://github.com/prometheus/blackbox_exporter

阅读 1058 · 发布于 2022-02-21

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批