javaspringspring-bootmbeansspring-jmx

Springboot 2.0 alternative to JmxMetricWriter


I am currently working on upgrading to SpringBoot 2.0.3.RELEASE. @ExportMetricWriter, MetricWriter, and JmxMetricWriter are no longer supported.

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

Whats the alternative in 2.0.


Solution

  • Spring Boot 2 now relies on Micrometer in order to export Metrics data to monitoring systems, such as New Relic and Graphite.

    Micrometer is a metrics instrumentation library for JVM-based applications. It provides a simple facade over the instrumentation clients for the most popular monitoring systems, allowing you to instrument your JVM-based application code without vendor lock-in.

    Meters are created and managed by Meter Registries, a fundamental concept in Micrometer. Each supported monitoring system has it's own implementation of a MeterRegistry. Data is exported in a transparent way to the backend of the monitoring system.

    The Spring Boot 1.5 way of exporting data to JMX, Redis, StatsD ... using Metric writers and exporters is no longer supported.

    Having said that, it doesn't mean you can't export metrics data to JMX anymore. You just don't have to declare a bean that implements a MetricWriter, annotate it with @ExportMetricWriter etc.

    Instead, all you have to do is to declare dependency on micrometer-registry-jmx which auto-configures a JmxMeterRegistry which exposes metrics to JMX. By default, under the metrics domain.

    For more details see the production-ready-metrics-export-jmx