spring-boot - 使用 Dropwizard 将 Spring Boot Actuator Metrics 导出到 Jmx 或 Graphite

标签 spring-boot dropwizard metrics spring-boot-actuator

我想使用 Spring Boot MetricsWriter将数据从 Spring Boot 应用程序写入/导出到我选择的数据源(例如 - Jmx/Graphite)。我可以用 JmxReporter/GraphiteReporter ,但我猜是 Spring 对 Writer 的抽象/Exporter可以在以后的数据源更改方面发挥至关重要的作用。

我的 REST 端点使用 Dropwizard 注释进行注释

@Timed(absolute=true, name="invokeEndpoint")
public ResponseEntity<Object> callSomeApi() {
   ...
}

我的配置类如下所示:
@Configuration
public class SpringBootMetrics {

    @Bean
    @ExportMetricReader
    public MetricReader metricReader() {
        return new MetricRegistryMetricReader(metricRegistry());
    }   

    public MetricRegistry metricRegistry() {
        final MetricRegistry metricRegistry = new MetricRegistry();
        return metricRegistry;
    }

    @Bean
    @ExportMetricWriter
    MetricWriter metricWriter(MBeanExporter exporter) {
        return new JmxMetricWriter(exporter);
    }
}

我没有看到通过我的 jconsole 在 Jmx 中收集端点调用的任何指标。我错过了什么?

最佳答案

在这种情况下唯一缺少的部分似乎是添加了 org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader到您的 Spring 配置,例如:

   @Bean
   MetricsEndpointMetricReader metricsEndpointMetricReader(MetricsEndpoint metricsEndpoint) {
      return new MetricsEndpointMetricReader(metricsEndpoint);
   }

关于spring-boot - 使用 Dropwizard 将 Spring Boot Actuator Metrics 导出到 Jmx 或 Graphite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43820661/

相关文章:

java - 获取 IllegalStateException : Session/EntityManager is closed on session. 逐出()

java - 如何在 GraphiteReporter 中添加自定义指标过滤器以仅发送选定的指标

java - Servlet Filter 似乎在 Dropwizard 中不起作用

dependency-injection - 使用 Dropwizard 从 Authenticator 访问 HttpServletRequest

kubernetes - 没有自定义指标的水平Pod自动缩放

publish-subscribe - 获取谷歌云 pubsub 的指标

alert - 如何显示队列中最旧的指标? Grafana/普罗米修斯

spring - Spring Boot依赖关系无法解决

java - Spring Boot 中是否可以更改基于时间的日志级别

mysql - spring jpa 加入和查询存储库