у меня есть:
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 только при выполнении запланированной задачи?