Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

path: util/aop/aop-service/src/main/java/com/knubisoft/aop/service/MethodExecutionTimeAspect.java

MethodExecutionTimeAspect works on the service layer and collects metrics about how long it took to execute and process the business logic of a particular method for each of its invocations (sum/max).

For counting we use the Micrometer library and its Timer, for each method, the first time it is called, a Timer is created using the TimerFactory and performs execution time count, if the Timer for method already exists, TimerFactory will return an existing instead of creating a new one.

MethodExecutionTimeAspect annotated with @ConditionalOnProperty(value = "management.serviceLayerMetrics.methodExecutionTimeEnabled", havingValue = "true"), so to 'enable' this aspect you must set the property management.serviceLayerMetrics.methodExecutionTimeEnabled within the application.yaml to true.

Image Added

Metrics we collect using Micrometer are also available for Prometheus (we create PrometheusMeterRegistry) and can be retrieved by the Spring Actuator endpoint your_host:your_port/actuator/prometheus

Image Added

Method execution time metrics can be requested from Prometheus by name service_method_execution_time_seconds_sum and service_method_execution_time_seconds_max, as you can see in the screenshot, each method has its own metric with a related Java service method name.

For metrics visualization we use Graphana and a specific dashboard (path: ops/grafana/application-dashboard-v2.json) where exists the method execution time panel