I have an Spring Boot application integrated with Dropwizard Metrics following this link.
When I added the @Timed annotation into some APIs (controller methods) it showed on the metrics link.
For example, for below RestController:
@RestController
public class TestController {
@GET
@Path("/ping")
@Timed
@ApiOperation("Ping server")
public Response Ping() {
return Response.ok().build();
}
}
then result is as follows:
"timers": {
"com.test.testcontroller.Ping": {
"count": 0,
"max": 0.0,
"mean": 0.0,
"min": 0.0,
"p50": 0.0,
"p75": 0.0,
"p95": 0.0,
"p98": 0.0,
"p99": 0.0,
"p999": 0.0,
"stddev": 0.0,
"m15_rate": 0.0,
"m1_rate": 0.0,
"m5_rate": 0.0,
"mean_rate": 0.0,
"duration_units": "seconds",
"rate_units": "calls/second"
}
}
I have around 20 controllers with a total of 130 APIs (methods) so I would like to configure a wide annotation or inject the @Timed annotation automatically. Something like:
@RestController
@Timed
public class TestController {
@GET
@Path("/ping")
@ApiOperation("Ping server")
// timed will auto applied in here
public Response Ping() {
return Response.ok().build();
}
}
How can I achieve that?
@Timedmetric instrumentation is not supported atClass(Controller) level. Here donw an excerpt of the adviced pointcut (from the metrics-spring integration library):As you can see from above excerpt,
@Timedannotations are only matched atmethodlevel.You will then have to either adapt the library sources and use a custom build for it (take good note of the library licence) or add the timer metric annotation explicitly over all you API methods.