gpt4 book ai didi

普罗米修斯 json 指标

转载 作者:行者123 更新时间:2023-12-02 19:52:33 27 4
gpt4 key购买 nike

我要监控的应用程序提供了一个用于健康检查的 api 端点,它以 json 格式响应指标。例如:

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

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

最佳答案

您可以使用 Prometheus JSON Exporter ( https://github.com/prometheus-community/json_exporter ) 调用您的服务并从 JSON 中提取值

将 Prometheus JSON Exporter 部署到它可以被 Prometheus 拉取并且 Exporter 可以访问您的 URL 的地方

对于您的 JSON 示例,JSON Exporter 的 config.xml 将类似于

---
metrics:
- name: user_count
path: "{$.data.UserCount}"
type: value
help: UserCount value
- name: user_count_active
path: "{$.data.UserCountActive}"
type: value
help: UserCountActive value

并在 Prometheus (prometheus.yml) 中抓取配置:

    ## gather the metrics from third party json sources, via the json exporter
- job_name: json_user_stat
metrics_path: /probe
static_configs:
- targets:
# URL of each API for json exporter
- https://example.com/api/stats
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
# Location of the json exporter's real <hostname>:<port> from Prometheus
replacement: json_exporter:7979

首先通过点击 URL 测试您的导出器(如果您想在浏览器之外使用,请编码“目标”值,浏览器将自动编码)http://json_exporter:7979/probe?target=https://example。 com/api/stats 并检查输出

# HELP UserCount value
# TYPE logstash_audit_events_in untyped
user_count{} 140
# HELP lUserCountActive value
# TYPE logstash_audit_events_out untyped
user_count_active{} 23

如果你明白了 - 在 Prometheus 中配置 scape 并享受你的指标

关于普罗米修斯 json 指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57844617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com