使用Prometheus scrape_config_files参数时遇YAML反序列化错误
问题描述
当将Sybase监控的Prometheus抓取配置直接写入主配置文件时,重载配置可正常加载;但将该配置单独存放于yml文件,通过主配置的scrape_config_files参数引用时,出现反序列化错误。
相关配置信息如下:
- 单独文件中的抓取任务配置:
- job_name: sybase-job basic_auth: username: "user" password: "password" honor_timestamps: true scheme: https scrape_interval: 30s scrape_timeout: 30s metrics_path: "/prometheus/metrics?tls=false&port=13603&target=10.10.10.10:12311&entity=NPASEX.SYB_UK-DEV-01&entity_type=SYBASE" tls_config: insecure_skip_verify: true follow_redirects: true static_configs: - targets: ["10.10.10.10:12311"]
- 主配置中的引用部分:
scrape_config_files: - /prom_config/dir/sybase/*.yml
- 完整错误信息:
May 14 13:11:49 promhost1 prometheus[1033]: ts=2024-05-14T12:11:49.650Z caller=main.go:1255 level=error msg="Failed to apply configuration" err="\"/prom_config/dir/sybase/npasex.syb_ukdev-01.yml\": yaml: unmarshal errors: line 1: cannot unmarshal !!seq into config.ScrapeConfigs"
问题原因与解决方法
- 原因:Prometheus主配置里的
scrape_configs是列表结构,所以每个任务前需要加-;但通过scrape_config_files加载的单个配置文件,其内容会被直接合并到scrape_configs列表中,不需要再用列表(开头的-)包裹任务。 - 解决方法:删除单独配置文件开头的
-,修改后的配置如下:
job_name: sybase-job basic_auth: username: "user" password: "password" honor_timestamps: true scheme: https scrape_interval: 30s scrape_timeout: 30s metrics_path: "/prometheus/metrics?tls=false&port=13603&target=10.10.10.10:12311&entity=NPASEX.SYB_UK-DEV-01&entity_type=SYBASE" tls_config: insecure_skip_verify: true follow_redirects: true static_configs: - targets: ["10.10.10.10:12311"]
内容的提问来源于stack exchange,提问作者trevp
相关产品推荐
相关产品推荐

