8

How @Counted works? I have added @Counted annotation on my method in Controller and expecting to see how many hits are coming to the controller. But i cannot see metrics added onto the url http://localhost:8080/actuator/prometheus.

 @Counted(value = "counted.success.test",description = "testCounter")
Reema Joshi
  • 133
  • 2
  • 9

1 Answers1

9

You need to add a CountedAspect as a bean, then the metrics are created when you call the method:

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class Config {

    @Bean
    CountedAspect countedAspect(MeterRegistry registry) {
        return new CountedAspect(registry);
    }

(Can't remember why we added the @EnableAspectJAutoProxy(proxyTargetClass = true))

Though that that kind of instumentation is not prefect, the labels class and method will change as soon as you refactor your code and your Grafana dashboard might not work any longer.

Jens Baitinger
  • 449
  • 2
  • 8