Search in sources :

Example 1 with MetricExporters

use of org.springframework.boot.actuate.metrics.export.MetricExporters in project spring-boot by spring-projects.

the class MetricExportAutoConfiguration method metricWritersMetricExporter.

@Bean
@ConditionalOnMissingBean(name = "metricWritersMetricExporter")
public SchedulingConfigurer metricWritersMetricExporter(MetricExportProperties properties) {
    Map<String, GaugeWriter> writers = new HashMap<>();
    MetricReader reader = this.endpointReader;
    if (reader == null && !CollectionUtils.isEmpty(this.readers)) {
        reader = new CompositeMetricReader(this.readers.toArray(new MetricReader[this.readers.size()]));
    }
    if (reader == null && CollectionUtils.isEmpty(this.exporters)) {
        return new NoOpSchedulingConfigurer();
    }
    MetricExporters exporters = new MetricExporters(properties);
    if (reader != null) {
        if (!CollectionUtils.isEmpty(this.writers)) {
            writers.putAll(this.writers);
        }
        exporters.setReader(reader);
        exporters.setWriters(writers);
    }
    exporters.setExporters(this.exporters == null ? Collections.<String, Exporter>emptyMap() : this.exporters);
    return exporters;
}
Also used : CompositeMetricReader(org.springframework.boot.actuate.metrics.reader.CompositeMetricReader) HashMap(java.util.HashMap) GaugeWriter(org.springframework.boot.actuate.metrics.writer.GaugeWriter) CompositeMetricReader(org.springframework.boot.actuate.metrics.reader.CompositeMetricReader) MetricReader(org.springframework.boot.actuate.metrics.reader.MetricReader) MetricsEndpointMetricReader(org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader) Exporter(org.springframework.boot.actuate.metrics.export.Exporter) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MetricExporters

use of org.springframework.boot.actuate.metrics.export.MetricExporters in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method defaultExporterWhenMessageChannelAvailable.

@Test
public void defaultExporterWhenMessageChannelAvailable() throws Exception {
    this.context = new AnnotationConfigApplicationContext(MessageChannelConfiguration.class, MetricRepositoryAutoConfiguration.class, MetricsChannelAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    MetricExporters exporter = this.context.getBean(MetricExporters.class);
    assertThat(exporter).isNotNull();
    assertThat(exporter.getExporters()).containsKey("messageChannelMetricWriter");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Example 3 with MetricExporters

use of org.springframework.boot.actuate.metrics.export.MetricExporters in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method provideAdditionalWriter.

@Test
public void provideAdditionalWriter() {
    this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricRepositoryAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    GaugeService gaugeService = this.context.getBean(GaugeService.class);
    assertThat(gaugeService).isNotNull();
    gaugeService.submit("foo", 2.7);
    MetricExporters exporters = this.context.getBean(MetricExporters.class);
    MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters().get("writer");
    exporter.setIgnoreTimestamps(true);
    exporter.export();
    MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
    Mockito.verify(writer, Mockito.atLeastOnce()).set(any(Metric.class));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MetricCopyExporter(org.springframework.boot.actuate.metrics.export.MetricCopyExporter) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) StatsdMetricWriter(org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter) MetricWriter(org.springframework.boot.actuate.metrics.writer.MetricWriter) Metric(org.springframework.boot.actuate.metrics.Metric) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Example 4 with MetricExporters

use of org.springframework.boot.actuate.metrics.export.MetricExporters in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method metricsFlushAutomatically.

@Test
public void metricsFlushAutomatically() throws Exception {
    this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricRepositoryAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    GaugeService gaugeService = this.context.getBean(GaugeService.class);
    assertThat(gaugeService).isNotNull();
    gaugeService.submit("foo", 2.7);
    MetricExporters flusher = this.context.getBean(MetricExporters.class);
    // this will be called by Spring on shutdown
    flusher.close();
    MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
    verify(writer, atLeastOnce()).set(any(Metric.class));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) StatsdMetricWriter(org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter) MetricWriter(org.springframework.boot.actuate.metrics.writer.MetricWriter) Metric(org.springframework.boot.actuate.metrics.Metric) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Example 5 with MetricExporters

use of org.springframework.boot.actuate.metrics.export.MetricExporters in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method exportMetricsEndpoint.

@Test
public void exportMetricsEndpoint() {
    this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    MetricExporters exporters = this.context.getBean(MetricExporters.class);
    MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters().get("writer");
    exporter.setIgnoreTimestamps(true);
    exporter.export();
    MetricsEndpointMetricReader reader = this.context.getBean("endpointReader", MetricsEndpointMetricReader.class);
    Mockito.verify(reader, Mockito.atLeastOnce()).findAll();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MetricCopyExporter(org.springframework.boot.actuate.metrics.export.MetricCopyExporter) MetricsEndpointMetricReader(org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Aggregations

MetricExporters (org.springframework.boot.actuate.metrics.export.MetricExporters)5 Test (org.junit.Test)4 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 MetricsEndpointMetricReader (org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader)2 GaugeService (org.springframework.boot.actuate.metrics.GaugeService)2 Metric (org.springframework.boot.actuate.metrics.Metric)2 MetricCopyExporter (org.springframework.boot.actuate.metrics.export.MetricCopyExporter)2 StatsdMetricWriter (org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter)2 MetricWriter (org.springframework.boot.actuate.metrics.writer.MetricWriter)2 HashMap (java.util.HashMap)1 Exporter (org.springframework.boot.actuate.metrics.export.Exporter)1 CompositeMetricReader (org.springframework.boot.actuate.metrics.reader.CompositeMetricReader)1 MetricReader (org.springframework.boot.actuate.metrics.reader.MetricReader)1 GaugeWriter (org.springframework.boot.actuate.metrics.writer.GaugeWriter)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1