I have a spring boot app with some REST APIs. I would like to collect usage metrics on these APIs. Metrics would be like how many times did a user hit the service in a time period. The user id is available in request header. Is there any framework that will help me with this reducing the boiler plate? Will splunk help?
3 Answers
Spring Boot Actuator seems what you need to have these metrics available. Here are some resources to get you started:
- https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-enabling
- https://www.baeldung.com/spring-boot-actuators
On top of the pre-defined metrics, you also have the ability to define custom metrics. Here's an answer to that: Spring boot actuator - Implement custom metrics
In our e-commerce project we use the DropWizard metrics:
https://github.com/dropwizard/metrics
https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-core
https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-healthchecks
With dropwizard you have timers, counters, meters, gauges, histograms, etc...
Getting started: https://metrics.dropwizard.io/3.1.0/getting-started/
Spring Boot actuators will give the info you are looking. But if you are looking for any sophisticated tool(which is for enterprise apps), I would suggest to check "Dynatrace", which is best for tracking the traffic and no.of hits to a given API, of course, it gives LOT of options. Check it. if your API is already configured in Splunk, then I think, in the dashboard you can track the incoming requests with which you can write the query to fetch your desired output.