Class TomcatServletMetricsFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class TomcatServletMetricsFilter
    extends Object
    implements javax.servlet.Filter
    A servlet filter that can be configured in Tomcat's global web.xml and that provides the following metrics: - A Histogram with response time distribution per context - A Gauge with the number of concurrent request per context - A Gauge with a the number of responses per context and status code

    If you are running Tomcat in the conventional non-embedded way you should add the client_tomcat jar and all its dependencies (see POM.XML) to the $CATALINA_BASE/lib directory or another directory on the common.loader path. Next, add this filter to the $CATALINA_BASE/lib/web.xml, e.g.:

     
     <filter>
       <filter-name>ServletMetricsFilter</filter-name>
       <filter-class>nl.nlighten.prometheus.TomcatServletMetricsFilter</filter-class>
       <async-supported>true</async-supported>
       <init-param>
         <param-name>buckets</param-name>
         <param-value>.01, .05, .1, .25, .5, 1, 2.5, 5, 10, 30</param-value>
       </init-param>
     </filter>
     
     
    If you running Tomcat embedded, please check AbstractTomcatMetricsTest for example configuration. Example metrics being exported:
         servlet_request_seconds_bucket{"/foo", "GET", "0.1",} 1.0
         ....
         servlet_request_seconds_bucket{"/foo", "GET", "+Inf",} 1.0
         servlet_request_concurrent_total{"/foo",} 1.0
         servlet_response_status_total{"/foo", "200",} 1.0
      
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig filterConfig)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
      • doFilter

        public void doFilter​(javax.servlet.ServletRequest servletRequest,
                             javax.servlet.ServletResponse servletResponse,
                             javax.servlet.FilterChain filterChain)
                      throws IOException,
                             javax.servlet.ServletException
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        IOException
        javax.servlet.ServletException
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Filter