读取 prometheustheus 时出错: bad_response: readObjectStart:expect { 或 n,但发现 #

6 python grafana prometheus

我的普罗米修斯服务器运行在http://localhost:8001/: 如果我通过浏览器浏览会显示以下内容:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 403.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
# HELP python_gc_objects_uncollectable_total Uncollectable object found during GC
# TYPE python_gc_objects_uncollectable_total counter
python_gc_objects_uncollectable_total{generation="0"} 0.0
python_gc_objects_uncollectable_total{generation="1"} 0.0
python_gc_objects_uncollectable_total{generation="2"} 0.0
# HELP python_gc_collections_total Number of times this generation was collected
# TYPE python_gc_collections_total counter
python_gc_collections_total{generation="0"} 39.0
python_gc_collections_total{generation="1"} 3.0
python_gc_collections_total{generation="2"} 0.0
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="3",minor="10",patchlevel="4",version="3.10.4"} 1.0
# HELP myorg_diskmetric_sizeInBytes Gets the size of the disk in bytes.
# TYPE myorg_diskmetric_sizeInBytes gauge
# HELP myorg_diskmetric_maxSizeInMegabytes Gets or sets the maximum size of the disk in megabytes, which is the size of memory allocated for the disk.
# TYPE myorg_diskmetric_maxSizeInMegabytes gauge
# HELP myorg_m_count Count of ping failures through count.
# TYPE myorg_m_count gauge
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在 Grafana 中配置相同的端点作为prometheus 数据源时,出现以下错误:

Error reading prometheusetheus: bad_response: readObjectStart: expect { or n, but found #, error found in #1 byte of ...|# HELP pyth|..., bigger context ...|# HELP python_gc_objects_collected_total Objects co|...
Run Code Online (Sandbox Code Playgroud)

Grafana ( v.9.0.5) 中的所有其他设置均为默认设置。

知道我在这里做错了什么吗?

小智 6

我使用 golang 中的 httpprom 生成类似的问题时遇到了这个问题:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 403.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
Run Code Online (Sandbox Code Playgroud)

这是您的指标示例,而不是普罗米修斯服务器的链接。您需要配置您的普罗米修斯服务器来抓取这些指标:例如。在 prometheus.yml 文件中:

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs:
- job_name: proxy
  metrics_path: /
  static_configs:
    - targets:
      - localhost:8001
Run Code Online (Sandbox Code Playgroud)

默认情况下,您的 prometheus 服务器应该在 localhost:9090 处可用。您可以检查 ui 进行确认,然后将该地址 localhost:9090 传递给 grafana,您将通过以下方式获取指标