@ -55,8 +55,6 @@ import org.springframework.util.CollectionUtils;
@EnableConfigurationProperties
public class MetricExportAutoConfiguration {
private final MetricExportProperties properties ;
private final MetricsEndpointMetricReader endpointReader ;
private final List < MetricReader > readers ;
@ -70,7 +68,6 @@ public class MetricExportAutoConfiguration {
@ExportMetricReader ObjectProvider < List < MetricReader > > readersProvider ,
@ExportMetricWriter ObjectProvider < Map < String , GaugeWriter > > writersProvider ,
ObjectProvider < Map < String , Exporter > > exportersProvider ) {
this . properties = properties ;
this . endpointReader = endpointReaderProvider . getIfAvailable ( ) ;
this . readers = readersProvider . getIfAvailable ( ) ;
this . writers = writersProvider . getIfAvailable ( ) ;
@ -79,7 +76,8 @@ public class MetricExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean ( name = "metricWritersMetricExporter" )
public SchedulingConfigurer metricWritersMetricExporter ( ) {
public SchedulingConfigurer metricWritersMetricExporter (
MetricExportProperties properties ) {
Map < String , GaugeWriter > writers = new HashMap < String , GaugeWriter > ( ) ;
MetricReader reader = this . endpointReader ;
if ( reader = = null & & ! CollectionUtils . isEmpty ( this . readers ) ) {
@ -89,7 +87,7 @@ public class MetricExportAutoConfiguration {
if ( reader = = null & & CollectionUtils . isEmpty ( this . exporters ) ) {
return new NoOpSchedulingConfigurer ( ) ;
}
MetricExporters exporters = new MetricExporters ( this . properties) ;
MetricExporters exporters = new MetricExporters ( properties) ;
if ( reader ! = null ) {
if ( ! CollectionUtils . isEmpty ( this . writers ) ) {
writers . putAll ( this . writers ) ;
@ -102,14 +100,19 @@ public class MetricExportAutoConfiguration {
return exporters ;
}
@Bean
@ExportMetricWriter
@ConditionalOnMissingBean
@ConditionalOnProperty ( prefix = "spring.metrics.export.statsd" , name = "host" )
public StatsdMetricWriter statsdMetricWriter ( ) {
MetricExportProperties . Statsd statsdProperties = this . properties . getStatsd ( ) ;
return new StatsdMetricWriter ( statsdProperties . getPrefix ( ) ,
statsdProperties . getHost ( ) , statsdProperties . getPort ( ) ) ;
@Configuration
static class StatsdConfiguration {
@Bean
@ExportMetricWriter
@ConditionalOnMissingBean
@ConditionalOnProperty ( prefix = "spring.metrics.export.statsd" , name = "host" )
public StatsdMetricWriter statsdMetricWriter ( MetricExportProperties properties ) {
MetricExportProperties . Statsd statsdProperties = properties . getStatsd ( ) ;
return new StatsdMetricWriter ( statsdProperties . getPrefix ( ) ,
statsdProperties . getHost ( ) , statsdProperties . getPort ( ) ) ;
}
}
@Configuration