1

I have few controllers in my SpringBoot application.

I know I can get total call counts on an endpoint using actuator.

However, I'm trying to find a way to get a total call count in last X days.

For example, how many times my endpoint was called in last 10 days?

pixel
  • 9,653
  • 16
  • 82
  • 149

2 Answers2

2

I think using actuator alone is not good for this task. What is the application gets restarted? What if tomorrow you'll want to analyze last 7, 14, 20 days? In general a better approach is putting all this data into some specialized db style storage (prometheus, datadog, influxdb, etc.) And using visualization tools like grafana for building the queries that will calculate what you need in an accessible and visually appealing form

Now its possible to create a model in memory that will maintain daily based counters and add a gauge that, when called, will retrieve this kind of data and will show, but then again, because of potential drawbacks that I've described at the beginning of the answer think whether it worth developing and maintaining such a solution

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
1

You can use the Spring Boot Actuator to get the details. It will not only provide the count for the API hits but also provide the duration, status response code any many more details and you can filter them as required.

You just need to add the following dependency in the pom file:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

Then try hitting the below URL:

http://localhost:8080/actuator/metrics/http.server.requests

In the response you will get the required details.

To get the details for the last X days you could store the data in a file or database (based on your requirements) and then query the same to get the desired result.

Hope that helps.

More details can be found here

inkredusk
  • 919
  • 4
  • 16