Search code examples
javaspring-webfluxmetricsspring-boot-actuator

When Spring actuator meets Spring Metrics in a Webflux project


I have a a small question: What are the benefits (if any) of using both Spring actuator plus Spring metrics in a Spring Webflux project please?

From the past years, it seems actuator is becoming more and more popular. However, in the "Spring ecosystem" there is this Spring metrics project.

Any benefits in combining the two? Or just one over the other is enough (in which case, which one)? Maybe some uses cases only having both together can be achieve?

Finally, I would like to track the time elapsed executing something in a Webflux project. Such as:

  • How many times was a webflux endpoint invoked?
  • How much time spent between receiving and responding to the request?
  • How much time needed for the reactive database call?
  • How much time spent executing this service?

etc... without hopefully having to reinvent the wheel. Any suggestion of a framework Spring friendly capable of achieving this?

Thank you


Solution

  • You do not need to use both libraries. Actuator is the only library you will need for instrumenting your spring boot application. Actuator uses Micrometer as it's underlying metrics library. It looks like Spring-metrics was created before this integration was moved into Actuator. I don't believe spring-metrics is a supported or maintained library anymore.

    How many times was a webflux endpoint invoked?

    How much time spent between receiving and responding to the request?

    Actuator ships with a WebFilter that instruments every http call made to your system. This is enabled by default. Docs

    How much time needed for the reactive database call?

    I don't believe there is any instrumentation for this out of the box but you can use Micrometer to add custom code to time each db call. Micrometer Timer Docs

    How much time spent executing this service?

    Similar to above.

    There is a lot of out of the box support for instrumenting different parts of your code base in spring boot. The best place to look to understand what is given to you is the documentation