I\'m trying to export all of the metrics which are visible at the endpoint /metrics to a StatsdMetricWriter.
I\'ve got the following config
To register JVM metrics you can use the JVM related MetricSets supplied by codehale.metrics.jvm library. You can just add the whole set without supplying whether they are gauges or counters.
Here is my example code where I am registering jvm related metrics:
@Configuration
@EnableMetrics(proxyTargetClass = true)
public class MetricsConfig {
@Autowired
private StatsdProperties statsdProperties;
@Autowired
private MetricsEndpoint metricsEndpoint;
@Autowired
private DataSourcePublicMetrics dataSourcePublicMetrics;
@Bean
@ExportMetricReader
public MetricReader metricReader() {
return new MetricRegistryMetricReader(metricRegistry());
}
public MetricRegistry metricRegistry() {
final MetricRegistry metricRegistry = new MetricRegistry();
//jvm metrics
metricRegistry.register("jvm.gc",new GarbageCollectorMetricSet());
metricRegistry.register("jvm.mem",new MemoryUsageGaugeSet());
metricRegistry.register("jvm.thread-states",new ThreadStatesGaugeSet());
return metricRegistry;
}
@Bean
@ConditionalOnProperty(prefix = "metrics.writer.statsd", name = {"host", "port"})
@ExportMetricWriter
public MetricWriter statsdMetricWriter() {
return new StatsdMetricWriter(
statsdProperties.getPrefix(),
statsdProperties.getHost(),
statsdProperties.getPort()
);
}
}
Note: I am using spring boot version 1.3.0.M4