为什么 CounterService 无法统计调用方法的次数?

Why CounterService fails to count the times a method was invoked?

我正在使用 spring AOP 和 spring 启动 CounterService 来记录特定方法的调用次数。每次访问目标 url 时,都会执行 countServiceInvoke,但输出指标值始终为 1"gauge.servo.string_com.yirendai.oss.environment.admin.controller.restcontrollertest.test()": 1

我想知道为什么这个计数器失败了?谢谢。 util class 如下所示:

@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() + "");
  }

}

我已经阅读了CounterService实现的class的源代码,为了正确计数,key应该以"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);
        }
    }