Nightingale HTTP_Response 探测插件实战:连通性、延迟与 HTTPS 证书过期监控

发布时间:2026/9/15 21:59:36
Nightingale HTTP_Response 探测插件实战:连通性、延迟与 HTTPS 证书过期监控 Nightingale HTTP_Response 探测插件实战连通性、延迟与 HTTPS 证书过期监控【免费下载链接】nightingaleNightingale is to monitoring and alerting what Grafana is to visualization.项目地址: https://gitcode.com/GitHub_Trending/ni/nightingaleHTTP_Response 是夜莺Nightingale监控体系中面向 HTTP/HTTPS 端点的一类探测插件由采集端 Categraf 执行用于检测目标地址的连通性、请求延迟以及 HTTPS 证书的过期时间。本文以仓库中的 HTTP_Response 集成说明 为核心骨架结合仓库内的完整配置模板、指标定义与预置告警规则讲解如何配置 targets、理解探测结果状态码的语义、编写告警规则并完成排障。为什么需要 HTTP 拨测以及为什么用数字表示结果在 Prometheus 生态中时序数据库只能存储 float64 类型的值因此 HTTP 地址探测的结果也被设计为 float64。但该值并非耗时或字节数而是一个结果状态码不同取值代表不同含义。这个指标的名称是http_response_result_codeSuccess 0 ConnectionFailed 1 Timeout 2 DNSError 3 AddressError 4 BodyMismatch 5 CodeMismatch 6一切正常时值为 0出现异常时值为 1~6各取值含义如上。由于告警表达式可以直接写成http_response_result_code ! 0这种0 正常、非 0 异常的设计让告警规则变得非常简洁仓库预置的告警规则 http_response_by_categraf.json 正是这样实现的。仓库的指标字典 etc/metrics.yaml 对相关指标也有说明例如http_response_result_code的中文释义为url探测结果0为正常否则url无法访问http_response_response_time为http响应用时。最核心的配置targets配置文件为 Categraf 采集器目录下的http_response.toml仓库内对应的模板是 integrations/HTTP_Response/collect/http_response/http_response.toml。最核心的配置项是targets用于配置目标探测地址。例如监控两个地址[[instances]] targets [ http://localhost:8080, https://www.baidu.com ]instances 的作用域共享配置与拆分同一个[[instances]]下的所有 targets共享该 section 下的全部设置如超时时间、HTTP 方法、请求头等。如果某些目标需要不同的配置就拆成多个[[instances]]例如一个用 GET、一个用 POST[[instances]] targets [ http://localhost:8080, https://www.baidu.com ] method GET [[instances]] targets [ http://localhost:9090 ] method POST这种实例instance模型与 Categraf 整体采集框架一致每个 instance 是一组独立配置的采集任务便于按业务维度拆分目标组也便于为不同目标组配置不同的labels与interval_times。为不同目标批量附加标签mappings在完整模板中还有一个位于文件顶部的[mappings]段用于按目标地址批量映射额外标签本功能见 http_response.toml[mappings] # http://localhost { job local } # https://www.baidu.com { job baidu }它可以把不同目标标记为不同的job等标签方便在告警规则和仪表盘中按业务维度聚合与筛选无需为每个目标单独写一个 instance。完整配置模板逐项解析以下为带注释的完整配置与仓库模板 http_response.toml 一致逐项说明参数的作用## collect interval # interval 15 ## Set the mapping of extra tags in batches [mappings] # http://localhost { job local } # https://www.baidu.com { job baidu } [[instances]] targets [ # http://localhost, # https://www.baidu.com ] ## append some labels for series # labels { regioncloud, productn9e } ## interval global.interval * interval_times # interval_times 1 ## Set http_proxy (categraf uses the system wide proxy settings if its is not set) # http_proxy http://localhost:8888 ## Interface to use when dialing an address # interface eth0 ## HTTP Request Method # method GET ## Set response_timeout (default 5 seconds) # response_timeout 5s ## Whether to follow redirects from the server (defaults to false) # follow_redirects false ## Optional HTTP Basic Auth Credentials # username username # password pa$$word ## Optional headers # headers [Header-Key-1, Header-Value-1, Header-Key-2, Header-Value-2] ## Optional HTTP Request Body # body # {fake:data} # ## Optional substring or regular expression match in body of the response(substring case sensitive). ## When both of the following parameters are enabled, one of them can be satisfied. # expect_response_substring ok # expect_response_regular_expression green|yellow ## Optional expected response status codes. ## expect_response_status_codes Supports adding multiple codes by delimiter(| or ,). ## When both of the following parameters are enabled, one of them can be satisfied. # expect_response_status_code 0 # expect_response_status_codes 200|301 ## Optional TLS Config # use_tls false # tls_ca /etc/categraf/ca.pem # tls_cert /etc/categraf/cert.pem # tls_key /etc/categraf/key.pem ## Use TLS but skip chain host verification # insecure_skip_verify false各参数要点配置项作用与说明interval采集周期秒位于文件顶部的全局段mappings按目标地址批量附加标签如jobtargets目标地址列表本插件的核心配置labels为整个 instance 的序列附加固定标签interval_times该 instance 的实际采集间隔 全局interval×interval_timeshttp_proxy设置 HTTP 代理未设置时 Categraf 使用系统全局代理设置interface拨号dial时使用的网卡例如eth0适用于多网卡主机指定出口methodHTTP 请求方法默认GETresponse_timeout响应超时时间默认 5 秒例如5sfollow_redirects是否跟随服务端重定向默认falseusername/passwordHTTP Basic Auth 认证凭据可选headers自定义请求头以键-值成对平铺的数组形式配置body可选的 HTTP 请求体支持多行字符串expect_response_substring期望响应体包含的子串大小写敏感expect_response_regular_expression期望响应体匹配的正则表达式expect_response_status_code期望的单个响应状态码expect_response_status_codes期望的多个状态码用\|或,分隔例如200\|301use_tls/tls_ca/tls_cert/tls_key启用 TLS 并配置 CA、客户端证书与私钥路径insecure_skip_verify使用 TLS 但跳过证书链与主机名校验注意模板中关于或语义的说明当expect_response_substring与expect_response_regular_expression同时启用时满足其一即视为通过expect_response_status_code与expect_response_status_codes同理二者同时启用时满足其一即可。这一逻辑直接影响CodeMismatch结果码 6与BodyMismatch结果码 5是否被触发配置时应与实际校验意图保持一致避免配置本身造成误报。输出的指标与状态码映射仓库的指标字典 integrations/HTTP_Response/metrics/categraf.json 定义了该插件上报的核心指标包含中英文名称与单位指标名含义单位http_response_result_code探测结果状态码0 正常1~6 各表异常同前文取值表nonehttp_response_response_code目标返回的 HTTP 响应码未拿到响应时该指标无值nonehttp_response_response_time探测整体耗时secondshttp_response_cert_expire_timestampHTTPS 证书过期时间戳datetimeSeconds其中http_response_response_code的字典注解特别提示如果没有拿到 response这个指标就没有值了因此在写告警时若依赖该指标应留意无值场景例如目标完全不可达时此时更适合用http_response_result_code表达故障状态。预置告警规则与查询语句仓库为 HTTP_Response 提供了两条默认默认 disabled的 PromQL 告警规则见 http_response_by_categraf.jsonhttp detect failedHTTP 探测失败评估周期 15 秒持续 60 秒触发级别 severity 2http_response_result_code ! 0即结果码非 0 即告警覆盖连接失败、超时、DNS 错误、地址错误、内容不匹配、状态码不匹配等全部异常分支。https certificate will expire within 7 daysHTTPS 证书 7 天内过期(http_response_cert_expire_timestamp - time())/86400 7用证书过期时间戳与当前时间之差除以 86400一天的秒数判断剩余天数是否小于等于 7实现证书临期预警可在续签失败前留出处理窗口。两条规则的annotations.action均给出了可操作的排障指引中英文见 i18n/en_US.json可直接作为告警通知中的处置建议探测失败在采集机上手工curl -sv 目标URL复现区分连接失败、超时、状态码不符连接失败先确认目标端口通、进程存活状态码不符则查看目标服务日志最后核对探测配置的超时、期望状态码与证书校验是否与实际相符避免配置导致误报。证书临期用echo | openssl s_client -connect 域名:443 -servername 域名 2/dev/null | openssl x509 -noout -dates确认到期时间与签发链走 ACME/certbot 自动续期的检查续期定时任务与上次执行日志确认续期后是否 reload 了服务手工证书立即联系签发方续签部署部署后用同一命令复验并确认所有节点含 CDN、负载均衡都已更新。配套仪表盘与指标落地仓库还提供了配套仪表盘模板 http_response_by_categraf.json其中包含按target维度聚合的 URL Details 面板用颜色映射展示每个 URL 的探测状态值为 0 显示为绿色 UP值大于等于 1 显示为红色 DOWN并用humantimeSeconds展示证书剩余有效期临近 7 天标红、临近 30 天标橙可直接导入夜莺的仪表盘模块查看多目标拨测总览。此外指标字典中的cdn_*系列指标如cdn_dns_request、cdn_tcp_connect、cdn_tls_handshake、cdn_first_byte、cdn_total_cost、cdn_response_status_code、cdn_probe_result_code对应拨测场景下更细粒度的分阶段耗时与状态码可作为深度排查延迟问题的补充数据来源。使用与排障要点总结从配置targets起步先验证最简单的连通性同一组配置的目标放在同一个[[instances]]差异大的目标拆分 instance。用http_response_result_code ! 0作为统一的故障入口告警再结合http_response_response_time、http_response_response_code定位是延迟、返回码还是内容问题。HTTPS 场景务必开启证书过期指标监控复用(http_response_cert_expire_timestamp - time())/86400 7规则提前预警。期望校验子串、正则、状态码只配置实际需要的项并理解多条件满足其一即通过的语义防止配置与预期不符造成误报。目标不可达时http_response_response_code可能无值故障判定应以http_response_result_code为准。【免费下载链接】nightingaleNightingale is to monitoring and alerting what Grafana is to visualization.项目地址: https://gitcode.com/GitHub_Trending/ni/nightingale创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考