Prometheus+Grafana+BlackBox黑盒监控Web

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

Blackbox_exporter 可以对一下场景进行监控:

  • HTTP 测试定义 Request Header 信息判断 Http status / Http Respones Header / Http Body 内容
  • TCP 测试业务组件端口状态监听应用层协议定义与监听
  • ICMP 测试主机探活机制
  • POST 测试接口联通性SSL 证书过期时间

在之前的运维中,因为忘了更换证书有些服务挂了一会,虽然很快恢复了但是也让我出一身冷汗。一开始我是用shell写了一个脚本定时执行来监听证书的时间,后来发现blackbox-exporter可以对证书等多中黑盒状态进行探测,所以也应用到了线上,这个场景比较适用免费证书的应用,因为现在你在购买证书的时候一般到期前都会给你收集发短信一类的通知,云场景就更不用说了,部署完了之后会有消息通知的策略设置。

1.安装blackbox_exporter

# 创建文件夹
root@ubuntu2204-98:~# cd /usr/local/prometheus_monitor/
root@ubuntu2204-98:/usr/local/prometheus_monitor# mkdir blackbox_exporter
root@ubuntu2204-98:/usr/local/prometheus_monitor# cd blackbox_exporter
# 创建docker-compose文件,启动
root@ubuntu2204-98:/usr/local/prometheus_monitor/blackbox_exporter# vi docker-compose.yml 
version: '3'
services:
    blackbox_exporter:
        image: prom/blackbox-exporter:master
        ports:
          - 9115:9115
        restart: unless-stopped
root@ubuntu2204-98:/usr/local/prometheus_monitor/blackbox_exporter# docker-compose up -d

2.创建blackbox监控Web列表

root@ubuntu2204-98:/usr/local/prometheus_monitor/blackbox_exporter# cd /usr/local/prometheus_monitor/prometheus
root@ubuntu2204-98:/usr/local/prometheus_monitor/prometheus# mkdir blackbox_monitor
root@ubuntu2204-98:/usr/local/prometheus_monitor/prometheus# cd blackbox_monitor
root@ubuntu2204-98:/usr/local/prometheus_monitor/prometheus/blackbox_monitor# vi blackbox-exporter.yaml
# 定义要监控的网站
- targets:
  - https://gitlab.xxx.top   # Target to probe with http.
  - https://jenkins.xxx.top/login?from=%2F  # Target to probe with https.
  - https://chatnext.xxx.top # Target to probe with http on port 8080.
  - https://drawio.xxxx.top # Target to probe with http on path /healthz

3.Prometheus加入blackbox

root@ubuntu2204-98:/usr/local/prometheus_monitor/prometheus/blackbox_monitor# cd ..
root@ubuntu2204-98:/usr/local/prometheus_monitor/prometheus# vi prometheus.yml 

  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.1.98:9115 # The blackbox exporter's real hostname:port.
    static_configs:
    file_sd_configs:
    - files:
      - /etc/prometheus/blackbox_monitor/blackbox-exporter.yaml

4.导入模板

模板id:9965

image-20250831095800345

image-20250831095800345

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值