我正在使用 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>
我有一个类可以收集这些指标并发送给 influx,请参阅:
@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