How to solve Prometheus configuration error: file service discovery config must contain at least one path name

How to solve Prometheus configuration error: file service discovery config must contain at least one path name

我一直在努力解决这个问题。我正在尝试在我的 prometheus.yml 文件中配置一个 file_sd_configs 部分。这是相关部分:

scrape_configs:
  - job_name: ct_agents
    file_sd_configs:
      - files:
        - agent_configs/agents.json

启动时,我收到此错误:

time="2019-02-07T16:15:21Z" level=error msg="Couldn't load configuration (-config.file=/etc/prometheus/prometheus.yml): file service discovery config must contain at least one path name" source="main.go:208"

我根据在别处找到的示例尝试了多种方法。我试过像一个例子一样将路径放在单引号中。我试过完整路径。我最初有一个通配符和一个空目录,希望 Prometheus 能找到可能的动态文件列表。

我已经多次检查间距。文件中没有标签(我在编辑 .yml 文件时遇到的最常见问题)。

文件本身存在,但目前只是一个空数组(在 JSON 中)。

我敢肯定这很傻。

错误信息中对错误进行了详细描述:

file service discovery config must contain at least one path name

因此,这意味着您的 json 文件应该至少有一个目标

  [
    {
      "targets": 
      "example.com"
      ],
    }
  ]

好的,感谢 Oliver 的问题,我们确定我是 运行 旧版本的 Prometheus(使用 apt-get install prometheus 安装)。安装现代版本很痛苦,但是一旦我重新配置它就解决了问题。

所以 - 如果有人在使用相同错误时遇到问题,请检查日志以查看您的 Prometheus 二进制文件有多旧。截至 2019 年 2 月,如果您在 Docker Ubuntu 实例上使用 apt-get 安装,您将获得非常非常旧的 Prometheus 副本。