【问题标题】:Parsing JSON rest api response in Prometheus在 Prometheus 中解析 JSON rest api 响应
【发布时间】:2020-01-04 11:07:29
【问题描述】:

目前我有一个 Kubernetes 环境并使用 Py rometheus 工具包进行监控。我有未在容器指标中公开的应用程序计数器。但是,我可以使用 curl 命令将它们视为 JSON 对象。

http://10.0.0.1:8081/api/events/

我使用 NodePort 通过工作节点的 IP 向外部公开 POD。

响应格式如下:

{
{
  "ID":   "001",
  "source": "pageloads",
  "summary":  "high failure counts",
  "severity": "major"
},
{
  "ID":   "003",
  "source": "profile_counts",
  "summary":  "profile count doesn't match number of groups",
  "severity": "minor"
},
{
  "ID":   "002",
  "source": "number of subscribers",
  "summary":  "profiles higher than subscribers",
  "severity": "critical"
}
}

有没有办法在 Prometheus 中包含 API 响应以每 15 秒轮询一次?

【问题讨论】:

  • 您是否在询问如何配置 Prometheus 以从您的应用中抓取指标?
  • 可以,但无需对应用程序进行额外配置。既然我已经可以得到 json 响应,我可以配置 prometheus 来抓取指标吗?

标签: kubernetes prometheus grafana


【解决方案1】:

该 json 响应不在 prometheus format 中,因此 prometheus 将无法抓取它。您将需要使用特定于语言的 prometheus 客户端库来检测您的代码,以便在 /metrics 端点以 prometheus 格式公开指标。如果这不可能,那么您需要使用现有的exporter 或编写自定义导出器。此导出器作为单独的进程运行,将从您的应用程序 api 端点收集指标并创建普罗米修斯格式指标并在 /metrics 端点公开这些指标。然后,您可以配置 prometheus 以抓取导出器的 /metrics 端点。

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多