【问题标题】:Prometheus API returning HTML instead of JSONPrometheus API 返回 HTML 而不是 JSON
【发布时间】:2019-03-31 00:01:14
【问题描述】:

使用 kubernates 配置 prometheus 并尝试使用 API 执行查询。按照文档配置和执行 API https://github.com/prometheus/prometheus/blob/master/docs/querying/api.md

执行下面的 curl 命令输出:

curl -k -X GET "https://127.0.0.1/api/v1/query?query=kubelet_volume_stats_available_bytes"

但是以 HTML 而不是 JSON 格式输出。

是否需要进行任何其他配置才能为 prometheus 获取 json 格式的输出?

【问题讨论】:

  • 你得到的输出是什么?
  • 它返回的 HTML 登录页面
  • 如果你得到一个登录页面,我猜你的 Prometheus 前面设置了某种身份验证?如果是这样,您可能需要为您的请求提供某种身份验证令牌(例如 oauth2 不记名令牌)以在其请求标头中发送,以便通过登录页面。
  • 已经尝试使用命令 - curl --user test:aaa -k -X GET "127.0.0.1/api/v1/…"。但得到同样的错误

标签: json api kubernetes prometheus


【解决方案1】:

Per the Prometheus documentation,Prometheus “[不] 不提供任何服务器端身份验证、授权或加密”。

您似乎遇到了一些代理,因此您需要弄清楚如何通过该代理并通过 Prometheus。一旦你这样做了,你就会得到你所期望的响应。

【讨论】:

    【解决方案2】:

    当我在本地机器上运行 prometheus 时,它基于 Prometheus README.md 默认在端口 9090 上运行:

    * Install docker
    * change the prometheus.yml section called target
    #static_configs: (example)
    #      - targets: ['172.16.129.33:8080']
    the target IP should be your localhost IP. Just providing localhost also would work.
    * docker build -t prometheus_simple .
    * docker run -p 9090:9090 prometheus_simple
    * endpoint for prometheus is http://localhost:9090
    

    所以如果我把端口放在你的 curl 调用中,我就有了

    curl -k -X GET "https://127.0.0.1:9090/api/v1/query?query=kubelet_volume_stats_available_bytes"
    

    我得到:

     {"status":"success","data":{"resultType":"vector","result":[]}}
    

    【讨论】:

      猜你喜欢
      • 2017-03-28
      • 2020-08-12
      • 2022-01-04
      • 1970-01-01
      • 2015-10-10
      • 2022-01-01
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      相关资源
      最近更新 更多