我正在使用Spring Boot 2 + Influx + Spring AOP来收集系统中的指标。
所以,我有:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-influx</artifactId>
</dependency>
我有一个收集该指标并发送给大量用户的课程,请参阅:
@Aspect
@Configuration
@RequiredArgsConstructor
@Slf4j
public class TimerCounterAspect {
private final MicrometerFactory micrometerFactory;
@Around("@annotation(br.com.myproject.TimerCount)")
public Object around(ProceedingJoinPoint joinPoint) {
Timer.Sample sample = micrometerFactory.starTimer();
micrometerFactory.counterIncrement(joinPoint.getTarget().getClass());
Object oReturn;
try {
oReturn = joinPoint.proceed();
} catch (Throwable throwable) {
micrometerFactory.counterErrorIncrement(joinPoint.getTarget().getClass());
log.error("Falha ao processar JoinPoint", throwable);
throw new RuntimeException(throwable);
} finally {
micrometerFactory.stopTimer(joinPoint.getTarget().getClass(), sample);
}
return oReturn;
}
}
当我向Influx发送一些值时,效果很好,但是在未经我允许的情况下,spring继续发送“零值”,从而填充了我的Influx数据库。因此,我的influxDB显示如下内容:
0
0
0
334 (My sent value)
0
0
0
0
0
答案 0 :(得分:0)
您可以在yml文件中进行这样的配置。
management:
metrics:
export:
influx:
uri: http://localhost:8086
db: mydbName
step: 10s
步长值应与您的预期流量相关。这样您就不会在其中看到90%的零。