普罗米修斯 json 指标 [英] Prometheus json metrics

查看:218
本文介绍了普罗米修斯 json 指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要监控的应用程序为健康检查提供了一个 api 端点,该端点以 json 中的指标进行响应.举个例子:

The application I want to monitor provides an api endpoint for health checks that responds with metrics in json. As an example:

$ curl  https://example.com/api/stats
{"status":"success","code":0,"data":{"UserCount":140,"UserCountActive":23}}

我已设置 Prometheus blackbox_exporter 来监控此端点返回 200 Ok,但我也希望获得这些指标.我了解检测直接从应用程序导出这些数据.但是由于应用程序已经在 json 对象中导出了我想要的内容,我更喜欢不维护我自己的这个软件的分支以包含检测所需的 Prometheus 库的便利.我应该如何使用 json 中的指标?

I have setup the Prometheus blackbox_exporter to monitor that this endpoint returns 200 Ok however I'd ideally like to get those metrics too. I understand instrumentation exports this data directly from the application. But since the application is already exporting what I want in a json object, I would prefer the convenience of not maintaining my own fork of this software to include the Prometheus libraries necessary for instrumentation. How should I consume metrics that are in json?

推荐答案

目前没有官方导出器来抓取 JSON 端点.也许是因为 从头开始编写一个很容易和任何通用解决方案必须使用一些默认行为,例如从路径到数据构建度量的名称,而不考虑度量的类型;或任何要应用或解析日期的相关标签,仅举几例.

There is currently no official exporter to scrape JSON endpoint. Maybe because it is easy to write one from scratch and any general solution must use some default behaviors like building the name of the metric from the path to the data which doesn't take into account the type of the metric ; or any relevant label to apply or parse date to name a few.

您可以使用首选搜索引擎轻松找到可用的 JSON 导出器.他们可以很容易地替换 blackbox_exporter.鉴于提供的样本,它们应该很合适.

You will easily find available JSON exporters with your preferred search engine. They can readily replace the blackbox_exporter. And they should be a good fit given the sample provided.

我想提到的一个解决方案是 exporter_exporter 因为我发现它对实施很有用在等待临时出口商的同时迅速成为出口商.它可用于执行生成 prometheus 指标的脚本.在您的情况下,编写一个 Python 脚本来抓取 Json 端点并使用它在标准输出中编写相应的 prometheus 格式非常容易.

One solution, I would like to mention is the exporter_exporter because I have found it useful for implementing rapidly an exporter while waiting for an adhoc one. It can be used to execute scripts that produce prometheus metrics. In your case, it is quite easy to write a python script that scrape a Json endpoint and use it to write the corresponding prometheus format in standard output.

这篇关于普罗米修斯 json 指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆