Prometheus黑盒监控多模块配置异常:指定模块未生效问题排查
问题分析与解决方案
你的配置不正确,问题出在Job级别的params配置会覆盖单个目标的__param_module标签。
原因说明
Prometheus中,当你在Job级别通过params定义了全局查询参数(这里是module: [http_2xx_example]),该参数会被自动添加到所有探测请求中,且优先级高于目标自身携带的__param_*标签。因此,即便你给https://other_link2设置了__param_module: http_2xx_example_auth,最终还是会被Job级别的params覆盖,使用默认的http_2xx_example模块。
修复方案
有两种可行的修复方式:
方式一:移除Job级别的params,直接在static_configs中为每组目标指定模块
- job_name: "blackbox" metrics_path: /probe static_configs: # 第一组目标使用默认模块 - targets: - https://google.com - https://other_link1 labels: { __param_module: http_2xx_example } # 第二组目标使用认证模块 - targets: [https://other_link2] labels: { __param_module: http_2xx_example_auth } relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: my_fancy_addr
方式二:保留Job级别的默认params,通过relabel_configs覆盖特定目标的模块
- job_name: "blackbox" metrics_path: /probe # 设置默认模块 params: module: [http_2xx_example] static_configs: - targets: - https://google.com - https://other_link1 # 为需要特殊模块的目标添加自定义标签 - targets: [https://other_link2] labels: { module: http_2xx_example_auth } relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance # 新增规则:当目标存在module标签时,覆盖__param_module参数 - source_labels: [module] target_label: __param_module - target_label: __address__ replacement: my_fancy_addr
两种方式都能让https://other_link2正确使用http_2xx_example_auth模块进行探测。
内容的提问来源于stack exchange,提问作者The Trainer
相关产品推荐
相关产品推荐

