我使用spring AOP
和spring boot CounterService
来记录特定方法的调用次数。每次访问目标网址时,都会执行countServiceInvoke,但输出指标值始终为1
。 "gauge.servo.string_com.yirendai.oss.environment.admin.controller.restcontrollertest.test()": 1
。
我想知道为什么这个计数器失败了?谢谢。 util类就像下面一样:
@Aspect
@Component
public class ServiceMonitor {
@Autowired
private CounterService counterService;
@Before("execution(* com.yirendai.oss.environment.admin.controller.*.*(..))")
public void countServiceInvoke(JoinPoint joinPoint) {
System.out.println("@@@@@@@@@@@@@@@@@@" + joinPoint.getSignature());
counterService.increment(joinPoint.getSignature() + "");
}
}
答案 0 :(得分:2)
我已阅读已实施的CounterService类的源代码,应使用"meter."
启动密钥才能正确计算。
private void incrementInternal(String name, long value) {
String strippedName = stripMetricName(name);
if (name.startsWith("status.")) {
// drop this metric since we are capturing it already with
// ServoHandlerInterceptor,
// and we are able to glean more information like exceptionType from that
// mechanism than what
// boot provides us
}
else if (name.startsWith("meter.")) {
BasicCounter counter = counters.get(strippedName);
if (counter == null) {
counter = new BasicCounter(MonitorConfig.builder(strippedName).build());
counters.put(strippedName, counter);
registry.register(counter);
}
counter.increment(value);
}
else {
LongGauge gauge = longGauges.get(strippedName);
if (gauge == null) {
gauge = new LongGauge(MonitorConfig.builder(strippedName).build());
longGauges.put(strippedName, gauge);
registry.register(gauge);
}
gauge.set(value);
}
}