2017-01-10 34 views
0

我正在使用spring AOP和弹簧引导CounterService来记录特定方法的调用时间。每次访问目标url时,都会执行countServiceInvoke,但输出度量值始终为1"gauge.servo.string_com.yirendai.oss.environment.admin.controller.restcontrollertest.test()": 1为什么CounterService无法计算一个方法被调用的次数?

我想知道为什么这个计数器失败?谢谢。该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() + ""); 
    } 

} 

回答

1

我看了实现类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); 
     } 
    } 
+0

我也遇到了这个问题。不知道为什么它似乎没有记录。感谢您的调查。 – Krum

相关问题