news 2026/4/23 14:13:57

Prometheus Blackbox域名SSL证书监控并设置AlertManager告警

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Prometheus Blackbox域名SSL证书监控并设置AlertManager告警

blackbox exporter 是prometheus社区提供的黑盒监控解决方案,运行用户通过HTTP、HTTPS、DNS、TCP以及ICMP的方式对网络进行探测(主动监测主机与服务状态)。

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

安装Blackbox exporter

docker run -d -p 9115:9115 --name blackbox_exporter -v /root/prometheus/blackbox_exporter:/config prom/blackbox-exporter:master --config.file=/config/blackbox.yml

写入配置

cat >/root/prometheus/blackbox_exporter/blackbox.yml<<EOF modules: http_2xx: # http 检测模块 Blockbox-Exporter 中所有的探针均是以 Module 的信息进行配置 prober: http timeout: 30s http: valid_http_versions: ["HTTP/1.1", "HTTP/2"] valid_status_codes: [200] # 这里最好作一个返回状态码,在grafana作图时,有明示---陈刚注释。 method: GET preferred_ip_protocol: "ip4" http_post_2xx: # http post 监测模块 prober: http timeout: 10s http: valid_http_versions: ["HTTP/1.1", "HTTP/2"] method: POST preferred_ip_protocol: "ip4" tcp_connect: # TCP 检测模块 prober: tcp timeout: 10s EOF

重启blackbox-exporter

编辑Promethues配置文件

- job_name: 'blackbox_http_2xx' metrics_path: /probe params: module: [http_2xx] #配置get请求检测 static_configs: - targets: - https://xxx.cn relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: blackbox_exporter:9115 #blackbox地址和端口号 - job_name: 'blackbox_tcp_connect' # 检测某些端口是否在线 scrape_interval: 30s metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: - xxx.cn:4433 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: blackbox_exporter:9115 # blackbox-exporter 服务所在的机器和端口

Grafana 配置

Grafana模板推荐

16292

AlertManager

alertmanager告警配置如下

  • SSL证书小于30天发送告警
  • HTTP状态非200告警
- name: Blackbox 监控告警 rules: - alert: BlackboxSlowProbe expr: avg_over_time(probe_duration_seconds[1m]) > 1 for: 30m labels: severity: warning annotations: summary: telnet (instance $labels.instance ) 超时1秒 description: "VALUE = $value n LABELS = $labels " - alert: BlackboxProbeHttpFailure expr: probe_http_status_code <= 199 OR probe_http_status_code >= 400 for: 30m labels: severity: critical annotations: summary: HTTP 状态码 (instance $labels.instance ) description: "HTTP status code is not 200-399n VALUE = $value n LABELS = $labels " - alert: BlackboxSslCertificateWillExpireSoon expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 30 for: 30m labels: severity: warning annotations: summary: 域名证书即将过期 (instance $labels.instance ) description: "域名证书30天后过期n VALUE = $value n LABELS = $labels " - alert: BlackboxSslCertificateWillExpireSoon expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 7 for: 30m labels: severity: critical annotations: summary: 域名证书即将过期 (instance $labels.instance ) description: "域名证书7天后过期n VALUE = $value n LABELS = $labels " - alert: BlackboxSslCertificateExpired expr: probe_ssl_earliest_cert_expiry - time() <= 0 for: 30m labels: severity: critical annotations: summary: 域名证书已过期 (instance $labels.instance ) description: "域名证书已过期n VALUE = $value n LABELS = $labels " - alert: BlackboxProbeSlowHttp expr: avg_over_time(probe_http_duration_seconds[1m]) > 10 for: 30m labels: severity: warning annotations: summary: HTTP请求超时 (instance $labels.instance ) description: "HTTP请求超时超过10秒n VALUE = $value n LABELS = $labels "

重启prometheus

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/12 7:53:52

LobeChat反向代理配置指南:Nginx和Caddy如何正确设置?

LobeChat反向代理配置指南&#xff1a;Nginx和Caddy如何正确设置&#xff1f; 在构建现代AI聊天应用时&#xff0c;LobeChat 已成为许多开发者首选的前端界面。它基于 Next.js 打造&#xff0c;支持 OpenAI、Ollama 等多种大模型后端&#xff0c;具备插件系统、角色设定、语音输…

作者头像 李华
网站建设 2026/4/23 12:58:48

公司资产网站信息管理系统源码-SpringBoot后端+Vue前端+MySQL【可直接运行】

摘要 随着信息技术的快速发展&#xff0c;企业资产管理逐渐向数字化、智能化转型。传统的资产管理方式依赖人工记录和纸质档案&#xff0c;效率低下且容易出错&#xff0c;难以满足现代企业对数据实时性和准确性的需求。公司资产网站信息管理系统通过整合资产数据、优化管理流程…

作者头像 李华
网站建设 2026/4/22 18:25:46

PMX转VRM失败?终极修复指南:5步解决骨骼缺失问题

VRM模型在PMX转换过程中经常遇到骨骼缺失问题&#xff0c;特别是上半身骨骼的缺失会导致模型无法正常使用。这个免费教程将为您提供完整的解决方案&#xff0c;帮助您快速修复PMX转VRM过程中出现的各种骨骼问题。 【免费下载链接】VRM-Addon-for-Blender VRM Importer, Exporte…

作者头像 李华
网站建设 2026/4/12 17:25:55

原神帧率解锁完整指南:3步突破60帧限制

原神帧率解锁完整指南&#xff1a;3步突破60帧限制 【免费下载链接】genshin-fps-unlock unlocks the 60 fps cap 项目地址: https://gitcode.com/gh_mirrors/ge/genshin-fps-unlock 原神帧率解锁工具是一款专为《原神》玩家设计的性能优化神器&#xff0c;通过智能修改…

作者头像 李华
网站建设 2026/4/19 21:56:06

OpenCore Legacy Patcher完全攻略:三步让旧Mac重获新生

OpenCore Legacy Patcher完全攻略&#xff1a;三步让旧Mac重获新生 【免费下载链接】OpenCore-Legacy-Patcher 体验与之前一样的macOS 项目地址: https://gitcode.com/GitHub_Trending/op/OpenCore-Legacy-Patcher 还在为旧款Mac无法升级最新系统而烦恼吗&#xff1f;Op…

作者头像 李华