Class MetricsInterceptor

java.lang.Object
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
com.netflix.spinnaker.kork.web.interceptors.MetricsInterceptor
All Implemented Interfaces:
org.springframework.web.servlet.AsyncHandlerInterceptor, org.springframework.web.servlet.HandlerInterceptor

public class MetricsInterceptor extends org.springframework.web.servlet.handler.HandlerInterceptorAdapter
An interceptor that logs Controller metrics to an underlying Registry.

A `timer` will be created for each request with the following tags:

- controller name - controller method - status (2xx, 4xx, 5xx, etc.) - statusCode (200, 404, 500, etc.) - success (true/false depending on whether the request resulted in an exception) - cause (if success == false, the name of the raised exception)

  • Constructor Details

    • MetricsInterceptor

      @Deprecated public MetricsInterceptor(com.netflix.spectator.api.Registry registry, String metricName, Collection<String> pathVariablesToTag, Collection<String> controllersToExclude)
      Deprecated.
      Instead use the other constructor.
    • MetricsInterceptor

      public MetricsInterceptor(com.netflix.spectator.api.Registry registry, String metricName, Collection<String> pathVariablesToTag, Collection<String> queryParamsToTag, Collection<String> controllersToExclude)
      Parameters:
      registry - Underlying metrics registry
      metricName - Metric name
      pathVariablesToTag - Variables from the request uri that should be added as metric tags
      queryParamsToTag - Request parameters that should be added as metric tags
      controllersToExclude - Controller names that should be excluded from metrics
  • Method Details

    • preHandle

      public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception
      Throws:
      Exception
    • afterCompletion

      public void afterCompletion(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception
      Throws:
      Exception
    • getNanoTime

      protected Long getNanoTime()