Search in sources :

Example 1 with GaugeWriter

use of org.springframework.boot.actuate.metrics.writer.GaugeWriter in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method statsdWithHost.

@SuppressWarnings("unchecked")
@Test
public void statsdWithHost() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "spring.metrics.export.statsd.host=localhost");
    this.context.register(MetricEndpointConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    StatsdMetricWriter statsdWriter = this.context.getBean(StatsdMetricWriter.class);
    assertThat(statsdWriter).isNotNull();
    SchedulingConfigurer schedulingConfigurer = this.context.getBean(SchedulingConfigurer.class);
    Map<String, GaugeWriter> exporters = (Map<String, GaugeWriter>) ReflectionTestUtils.getField(schedulingConfigurer, "writers");
    assertThat(exporters).containsValue(statsdWriter);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GaugeWriter(org.springframework.boot.actuate.metrics.writer.GaugeWriter) StatsdMetricWriter(org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter) Map(java.util.Map) SchedulingConfigurer(org.springframework.scheduling.annotation.SchedulingConfigurer) Test(org.junit.Test)

Example 2 with GaugeWriter

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

use of org.springframework.boot.actuate.metrics.writer.GaugeWriter in project spring-boot by spring-projects.

the class MetricExporters method configureTasks.

@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    for (Entry<String, Exporter> entry : this.exporters.entrySet()) {
        String name = entry.getKey();
        Exporter exporter = entry.getValue();
        TriggerProperties trigger = this.properties.findTrigger(name);
        if (trigger != null) {
            ExportRunner runner = new ExportRunner(exporter);
            IntervalTask task = new IntervalTask(runner, trigger.getDelayMillis(), trigger.getDelayMillis());
            taskRegistrar.addFixedDelayTask(task);
        }
    }
    for (Entry<String, GaugeWriter> entry : this.writers.entrySet()) {
        String name = entry.getKey();
        GaugeWriter writer = entry.getValue();
        TriggerProperties trigger = this.properties.findTrigger(name);
        if (trigger != null) {
            MetricCopyExporter exporter = getExporter(writer, trigger);
            this.exporters.put(name, exporter);
            this.closeables.add(name);
            ExportRunner runner = new ExportRunner(exporter);
            IntervalTask task = new IntervalTask(runner, trigger.getDelayMillis(), trigger.getDelayMillis());
            taskRegistrar.addFixedDelayTask(task);
        }
    }
}
Also used : IntervalTask(org.springframework.scheduling.config.IntervalTask) GaugeWriter(org.springframework.boot.actuate.metrics.writer.GaugeWriter)

Aggregations

GaugeWriter (org.springframework.boot.actuate.metrics.writer.GaugeWriter)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 MetricsEndpointMetricReader (org.springframework.boot.actuate.endpoint.MetricsEndpointMetricReader)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 MetricReader (org.springframework.boot.actuate.metrics.reader.MetricReader)1 StatsdMetricWriter (org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 SchedulingConfigurer (org.springframework.scheduling.annotation.SchedulingConfigurer)1 IntervalTask (org.springframework.scheduling.config.IntervalTask)1