【问题标题】:Spring Boot metrics export to InfluxDB - how to reduce number of exports?Spring Boot 指标导出到 InfluxDB - 如何减少导出数量?
【发布时间】:2018-08-31 16:50:31
【问题描述】:

我有:

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?

【问题讨论】:

    标签: spring-boot micrometer spring-micrometer


    【解决方案1】:

    您可以使用management.metrics.export.influx.step 属性更改报告频率,如下所示:

    management.metrics.export.influx.step=1h
    

    【讨论】:

      猜你喜欢
      • 2017-03-16
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 2015-03-02
      • 2022-11-21
      相关资源
      最近更新 更多