【问题标题】:Push metrics to Prometheus Pushgateway in Spring Boot在 Spring Boot 中将指标推送到 Prometheus Pushgateway
【发布时间】:2017-06-15 08:21:02
【问题描述】:

我想推送指标,例如通过 Spring Boot 应用程序中的 Pushgateway 向 Prometheus 发送 HTTP 请求或当前堆大小的处理时间。

我正在苦苦挣扎,因为有很多来自 Spring Metrics 或 Prometheus 的文档,但它们都没有解决我的具体问题。

最简单的方法是在 RestController 类上使用 @Timed 注释,如下所述:http://projects.spring.io/spring-metrics/ 但是,我看不到,我可以在哪里为 pushgateway 配置 URL,并问自己 @Timed 注释是否只是将指标导出到应该从中提取它们的 /prometheus 端点。

然而,Prometheus 指南告诉我使用 simpleclient_pushgateway 库:https://github.com/prometheus/client_java#exporting-to-a-pushgateway

最后,还有一个名为simpleclient_spring_boot 的简单客户端,这是将Prometheus 集成到Spring Boot 中的第三种方式。

你能告诉我,我可以如何完成

A) 从基于注解的 HTTP 请求方法推送指标

B) 每 x 秒 JVM 指标的某种方法

C) 到可配置的(在application.yml 文件中)推送网关

非常感谢

【问题讨论】:

    标签: spring-boot prometheus prometheus-pushgateway


    【解决方案1】:

    这是错误的处理方式,推送网关不适用于堆大小或请求时间等每个实例的指标 (https://prometheus.io/docs/practices/pushing/)。

    您要做的是使用simpleclient_spring_boot 公开一个/metrics 端点,Prometheus 将直接抓取该端点。

    【讨论】:

    • 对不起,我应该说明为什么我需要 pushgateway :-) 我们的应用程序部署到 Cloud Foundry。根据当前响应请求的实例,使用 Prometheus 轮询它们会产生不同的值。这就是为什么我喜欢将每个实例的指标推送到推送网关并在 Grafana 中区分它们。
    • 这仍然不是推荐的处理方式。我相信 Cloud Foundry 的方法是做一些服务发现,然后做一些事情来添加一个 HTTP 标头来与正确的实例对话。
    • @brian-brazil - 你能解释一下为什么这不是正确的方法吗?假设有多个 Sprint 引导服务,它们充当多个工作人员。工人的数量是根据系统负载配置的(码头规模)。每个工作人员不暴露 HTTP 端口,而只是处理一些工作处理。它仍然是错误的方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    相关资源
    最近更新 更多