Search in sources :

Example 1 with MetricReader

use of org.springframework.boot.actuate.metrics.reader.MetricReader 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 MetricReader

use of org.springframework.boot.actuate.metrics.reader.MetricReader in project spring-boot by spring-projects.

the class MetricRepositoryAutoConfigurationTests method createServices.

@Test
public void createServices() throws Exception {
    this.context = new AnnotationConfigApplicationContext(MetricRepositoryAutoConfiguration.class);
    GaugeService gaugeService = this.context.getBean(BufferGaugeService.class);
    assertThat(gaugeService).isNotNull();
    assertThat(this.context.getBean(BufferCounterService.class)).isNotNull();
    assertThat(this.context.getBean(PrefixMetricReader.class)).isNotNull();
    gaugeService.submit("foo", 2.7);
    MetricReader bean = this.context.getBean(MetricReader.class);
    assertThat(bean.findOne("gauge.foo").getValue()).isEqualTo(2.7);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BufferGaugeService(org.springframework.boot.actuate.metrics.buffer.BufferGaugeService) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) MetricReader(org.springframework.boot.actuate.metrics.reader.MetricReader) PrefixMetricReader(org.springframework.boot.actuate.metrics.reader.PrefixMetricReader) Test(org.junit.Test)

Example 3 with MetricReader

use of org.springframework.boot.actuate.metrics.reader.MetricReader in project spring-boot by spring-projects.

the class MetricReaderPublicMetricsTests method exposesMetrics.

@Test
public void exposesMetrics() {
    List<Metric<?>> metrics = new ArrayList<>();
    metrics.add(mock(Metric.class));
    metrics.add(mock(Metric.class));
    MetricReader reader = mock(MetricReader.class);
    given(reader.findAll()).willReturn(metrics);
    MetricReaderPublicMetrics publicMetrics = new MetricReaderPublicMetrics(reader);
    assertThat(publicMetrics.metrics()).isEqualTo(metrics);
}
Also used : ArrayList(java.util.ArrayList) Metric(org.springframework.boot.actuate.metrics.Metric) MetricReader(org.springframework.boot.actuate.metrics.reader.MetricReader) Test(org.junit.Test)

Aggregations

MetricReader (org.springframework.boot.actuate.metrics.reader.MetricReader)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MetricsEndpointMetricReader (org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader)1 GaugeService (org.springframework.boot.actuate.metrics.GaugeService)1 Metric (org.springframework.boot.actuate.metrics.Metric)1 BufferGaugeService (org.springframework.boot.actuate.metrics.buffer.BufferGaugeService)1 Exporter (org.springframework.boot.actuate.metrics.export.Exporter)1 MetricExporters (org.springframework.boot.actuate.metrics.export.MetricExporters)1 CompositeMetricReader (org.springframework.boot.actuate.metrics.reader.CompositeMetricReader)1 PrefixMetricReader (org.springframework.boot.actuate.metrics.reader.PrefixMetricReader)1 GaugeWriter (org.springframework.boot.actuate.metrics.writer.GaugeWriter)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1