Package com.codahale.metrics.servlets
Class MetricsServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- com.codahale.metrics.servlets.MetricsServlet
-
- All Implemented Interfaces:
java.io.Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class MetricsServlet extends javax.servlet.http.HttpServletA servlet which returns the metrics in a given registry as anapplication/jsonresponse.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMetricsServlet.ContextListenerAn abstractServletContextListenerwhich allows you to programmatically inject theMetricRegistry, rate and duration units, and allowed origin forMetricsServlet.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALLOWED_ORIGINprivate java.lang.StringallowedOriginprivate static java.lang.StringCONTENT_TYPEstatic java.lang.StringDURATION_UNITprivate com.fasterxml.jackson.databind.ObjectMappermapperstatic java.lang.StringMETRICS_REGISTRYstatic java.lang.StringRATE_UNITprivate MetricRegistryregistryprivate static longserialVersionUIDstatic java.lang.StringSHOW_SAMPLES
-
Constructor Summary
Constructors Constructor Description MetricsServlet()MetricsServlet(MetricRegistry registry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)private com.fasterxml.jackson.databind.ObjectWritergetWriter(javax.servlet.http.HttpServletRequest request)voidinit(javax.servlet.ServletConfig config)private java.util.concurrent.TimeUnitparseTimeUnit(java.lang.String value, java.util.concurrent.TimeUnit defaultValue)-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
RATE_UNIT
public static final java.lang.String RATE_UNIT
-
DURATION_UNIT
public static final java.lang.String DURATION_UNIT
-
SHOW_SAMPLES
public static final java.lang.String SHOW_SAMPLES
-
METRICS_REGISTRY
public static final java.lang.String METRICS_REGISTRY
-
ALLOWED_ORIGIN
public static final java.lang.String ALLOWED_ORIGIN
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
CONTENT_TYPE
private static final java.lang.String CONTENT_TYPE
- See Also:
- Constant Field Values
-
allowedOrigin
private java.lang.String allowedOrigin
-
registry
private transient MetricRegistry registry
-
mapper
private transient com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Constructor Detail
-
MetricsServlet
public MetricsServlet()
-
MetricsServlet
public MetricsServlet(MetricRegistry registry)
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
getWriter
private com.fasterxml.jackson.databind.ObjectWriter getWriter(javax.servlet.http.HttpServletRequest request)
-
parseTimeUnit
private java.util.concurrent.TimeUnit parseTimeUnit(java.lang.String value, java.util.concurrent.TimeUnit defaultValue)
-
-