0

I have:

plugins {
  id 'org.springframework.boot' version '2.0.3.RELEASE' 
}

And:

compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'io.micrometer:micrometer-registry-influx:1.0.5'

I have scheduled task which should execute every 1h and export specific metrics from service to 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());
        });
    }
}

When I check logs, I see that they are exported every minute:

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

How to make metrics export to InfluxDB only when scheduled task is executed?

Johnny Lim
  • 5,623
  • 8
  • 38
  • 53
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114

1 Answers1

1

You can change the reporting frequency with the management.metrics.export.influx.step property as follows:

management.metrics.export.influx.step=1h
Johnny Lim
  • 5,623
  • 8
  • 38
  • 53