Spring boot 为什么CounterService无法计算调用方法的次数?
我使用Spring boot 为什么CounterService无法计算调用方法的次数?,spring-boot,spring-aop,spring-boot-actuator,Spring Boot,Spring Aop,Spring Boot Actuator,我使用springaop和springbootCounterService来记录特定方法的调用时间。每次访问目标url时,都会执行countServiceInvoke,但输出度量值始终为1“gauge.servo.string_com.yirendai.oss.environment.admin.controller.restcontrollertest.test()”:1 我想知道为什么这个计数器失败了?谢谢util类如下所示: @Aspect @Component public class
springaop
和springbootCounterService
来记录特定方法的调用时间。每次访问目标url时,都会执行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() + "");
}
}
我已经阅读了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);
}
}
我已经阅读了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);
}
}
我也碰到了这个问题。想知道为什么它似乎没有被记录下来。谢谢你的调查。我也遇到了这个问题。想知道为什么它似乎没有被记录下来。谢谢你的调查。