我有:
plugins {
id 'org.springframework.boot' version '2.0.3.RELEASE'
}
和:
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'io.micrometer:micrometer-registry-influx:1.0.5'
我已经安排了应该每 1 小时执行一次并将特定指标从服务导出到 InfluxDB 的任务:
@Profile("!test")
@Component
public class ExportMetricsTask {
@Autowired
private MetricsService metricsService;
@Autowired
private MeterRegistry meterRegistry;
@Scheduled(initialDelayString = "1000", fixedDelayString="3600000")
public void exportMetricsTask() {
metricsService.getSomeMetrics().forEach(response -> {
List<Tag> tags = Arrays.asList(Tag.of("country.iso2", response.getIso2()));
meterRegistry.gauge("countries.by.coverage.km",tags, response.getCoverageKm());
});
}
}
当我检查日志时,我看到它们每分钟都被导出:
2018-08-31_16:38:38.75242 2018-08-31 19:38:38.752 INFO 50712 --- [pool-1-thread-1] i.micrometer.influx.InfluxMeterRegistry : successfully sent 315 metrics to influx
2018-08-31_16:39:38.76281 2018-08-31 19:39:38.760 INFO 50712 --- [pool-1-thread-1] i.micrometer.influx.InfluxMeterRegistry : successfully sent 315 metrics to influx
如何仅在执行计划任务时才将指标导出到 InfluxDB?