Prometheus监控HTTPS端点报错:INVALID并非有效起始令牌
问题原因
报错的核心不是HTTPS scheme配置错误,而是你指定的metrics_path: '/v6/latest/USD'返回的是JSON格式的汇率数据,并非Prometheus可直接解析的OpenMetrics/Prometheus exposition格式(这类格式以# HELP/# TYPE开头)。Prometheus在尝试解析响应内容时,发现开头不是预期的metrics标识,从而抛出了误导性的scheme相关错误。
解决方案
根据你的需求,分两种场景处理:
场景1:仅监控端点是否可达(存活状态)
使用Blackbox Exporter来探测HTTPS端点的可用性,步骤如下:
- 部署Blackbox Exporter(Windows下可直接下载对应二进制包运行)
- 配置Blackbox Exporter的
blackbox.yml(示例):
modules: http_2xx: prober: http http: method: GET tls_config: insecure_skip_verify: true
- 修改Prometheus的
prometheus.yml,添加Blackbox的抓取配置,通过它来探测目标端点:
scrape_configs: - job_name: "blackbox" metrics_path: /probe params: module: [http_2xx] static_configs: - targets: - https://open.er-api.com/v6/latest/USD relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: localhost:9115 # Blackbox Exporter的地址
场景2:需要监控汇率数值(将JSON转为metrics)
你需要一个自定义exporter或者使用通用的JSON exporter来把目标端点的JSON数据转换成Prometheus metrics格式:
- 部署JSON Exporter(比如
prometheus-json-exporter,Windows下可下载二进制) - 配置JSON Exporter的
config.yml(示例,提取汇率数据):
modules: er_api: metrics: - name: exchange_rate_usd type: gauge path: "{$.rates.CNY}" # 假设你要监控人民币对美元的汇率,根据实际JSON结构调整 help: "CNY to USD exchange rate"
- 修改Prometheus的
prometheus.yml,添加JSON Exporter的抓取配置:
scrape_configs: - job_name: "exchange_rate" metrics_path: /probe params: module: [er_api] target: [https://open.er-api.com/v6/latest/USD] static_configs: - targets: - localhost:7979 # JSON Exporter的地址
额外说明
你的原配置中scheme: https和targets: ["open.er-api.com:443"]是正确的,问题出在目标端点的返回格式不符合Prometheus的抓取要求,和Windows操作系统无关。
内容的提问来源于stack exchange,提问作者Pratik
相关产品推荐
相关产品推荐

