Class MetricsServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
io.dropwizard.metrics.servlets.MetricsServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class MetricsServlet extends jakarta.servlet.http.HttpServlet
A servlet which returns the metrics in a given registry as an application/json response.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An abstract ServletContextListener which allows you to programmatically inject the MetricRegistry, rate and duration units, and allowed origin for MetricsServlet.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected String
     
    static final String
     
    static final String
     
    protected String
     
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    static final String
     
    static final String
     
    static final String
     
    protected com.codahale.metrics.MetricRegistry
     
    static final String
     

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    MetricsServlet(com.codahale.metrics.MetricRegistry registry)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     
    protected com.fasterxml.jackson.databind.ObjectWriter
    getWriter(jakarta.servlet.http.HttpServletRequest request)
     
    void
    init(jakarta.servlet.ServletConfig config)
     
    protected TimeUnit
    parseTimeUnit(String value, TimeUnit defaultValue)
     
    protected void
    setupMetricsModule(jakarta.servlet.ServletContext context)
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RATE_UNIT

      public static final String RATE_UNIT
    • DURATION_UNIT

      public static final String DURATION_UNIT
    • SHOW_SAMPLES

      public static final String SHOW_SAMPLES
    • METRICS_REGISTRY

      public static final String METRICS_REGISTRY
    • ALLOWED_ORIGIN

      public static final String ALLOWED_ORIGIN
    • METRIC_FILTER

      public static final String METRIC_FILTER
    • CALLBACK_PARAM

      public static final String CALLBACK_PARAM
    • allowedOrigin

      protected String allowedOrigin
    • jsonpParamName

      protected String jsonpParamName
    • registry

      protected transient com.codahale.metrics.MetricRegistry registry
    • mapper

      protected transient com.fasterxml.jackson.databind.ObjectMapper mapper
  • Constructor Details

    • MetricsServlet

      public MetricsServlet()
    • MetricsServlet

      public MetricsServlet(com.codahale.metrics.MetricRegistry registry)
  • Method Details

    • init

      public void init(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Servlet
      Overrides:
      init in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
    • setupMetricsModule

      protected void setupMetricsModule(jakarta.servlet.ServletContext context)
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • getWriter

      protected com.fasterxml.jackson.databind.ObjectWriter getWriter(jakarta.servlet.http.HttpServletRequest request)
    • parseTimeUnit

      protected TimeUnit parseTimeUnit(String value, TimeUnit defaultValue)