You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境Prometheus启动失败 报prometheus.yml YAML解析错误

故障原因

该错误为YAML配置缩进不符合语法规范导致。scrape_configs是数组类型配置项,其下所有以- job_name开头的采集任务必须保持统一缩进层级,属于scrape_configs的子元素。你提供的配置中,第二个采集任务wmi_Exporter对应的- job_name行顶格书写,没有和上方第一个prometheus采集任务的- job_name保持相同缩进,YAML解析器读取到第31行(即顶格的wmi_Exporter任务行)时,无法将其识别为scrape_configs下的合法子项,因此抛出解析失败错误。

排查解决步骤
  • 定位配置错误点:找到配置文件第31行的- job_name: "wmi_Exporter"配置块,将整个配置块缩进2个空格,和上方- job_name: "prometheus"的缩进层级完全对齐。
  • 修正后的合法配置参考如下:
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "wmi_Exporter"
    static_configs:
      - targets: ["10.10.10.1:9182"]
  • 配置保存后,先在Prometheus安装目录执行校验命令promtool.exe check config prometheus.yml,返回配置校验成功的提示后再启动Prometheus服务即可正常运行。

注意:YAML语法对缩进要求严格,禁止使用Tab键做缩进,必须统一使用空格控制缩进,同层级元素的缩进空格数必须完全一致,否则极易触发此类解析错误。

内容的提问来源于stack exchange,提问作者Roopesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 10:57:19