Search in sources :

Example 1 with MetricWriter

use of org.springframework.boot.actuate.metrics.writer.MetricWriter 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 2 with MetricWriter

use of org.springframework.boot.actuate.metrics.writer.MetricWriter 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)

Aggregations

Test (org.junit.Test)2 GaugeService (org.springframework.boot.actuate.metrics.GaugeService)2 Metric (org.springframework.boot.actuate.metrics.Metric)2 MetricExporters (org.springframework.boot.actuate.metrics.export.MetricExporters)2 StatsdMetricWriter (org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter)2 MetricWriter (org.springframework.boot.actuate.metrics.writer.MetricWriter)2 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 MetricCopyExporter (org.springframework.boot.actuate.metrics.export.MetricCopyExporter)1