How it works...

If you are familiar with annotations such as @Path, @GET, and @Produces, then the code of this recipe is not something new for you. So, how did we manage to get these metrics generated and checked?

We used two simple annotations— @Timed and @Metered:

@Timed(name = "getResourceTimed")

When we added this annotation to the getResourceTimed method, we were saying to the framework, please, collect timed metrics for this method:

@Metered(name = "getResourceMetered")

And there are also other metrics auto-generated by the framework. To check them, just open this URL:

http://localhost:8080/metrics

It will show you all of the metrics being collected so far (including yours).