1

I am writing my first spring boot (2.6.3) application.

Here the relevant dependencies I am using:

<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.6.3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </exclusion> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <scope>runtime</scope> </dependency> </dependencies> 

I exposed by actuator all the features:

management: endpoint: health: show-details: always endpoints: web: exposure: include: '*' info: env: enabled: true 

So I can see all the endpoints listed by the url /actuator.

Now, I added some annotations like @Counted and @Timed to some methods, I invoked them, but they don't show up into /actuator/metrics.

How could I solved that issue?

Thank you so much in advance!

2

2 Answers 2

4

Are you aware that @Timed annotations are supported on @Controller classes and @RequestMapping methods only?

https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.supported.spring-mvc

I am not sure @Counted is supported by default.

EDIT: The @Counted annotation doesn't work by default. To make it work, you'll need to add an CountedAspect to your context.

See: https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/aop/CountedAspect.java

Also, there's an open issue for @Counter auto-configuration: https://github.com/spring-projects/spring-boot/issues/17260

Sign up to request clarification or add additional context in comments.

2 Comments

I generated all the stuffs by Maven OpenAPI generator plugin using the Delegate Pattern. It generates the API interface, implemented by the Controller, and the latter one uses my delegate where I placed the meter annotations. Can they work here?
1.5 year passed, counted still doesn't work...
3

Solved by adding the following:

@Bean CountedAspect countedAspect(MeterRegistry registry) { return new CountedAspect(registry); } 
<dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.13</version> </dependency> 

It works with OpenAPI delegates too.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.