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);
}
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;
}
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);
}
}
}
Aggregations