public class MetricsServlet extends javax.servlet.http.HttpServlet implements MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
MetricsRegistry (and optionally the data
provided by VirtualMachineMetrics) in a JSON object. Only responds to GET
requests.
If the servlet context has an attribute named
com.yammer.metrics.reporting.MetricsServlet.registry which is a
MetricsRegistry instance, MetricsServlet will use it instead of Metrics.
MetricsServlet also takes an initialization parameter, show-jvm-metrics, which
should be a boolean value (e.g., "true" or "false"). It determines whether or not
JVM-level metrics will be included in the JSON output.
GET requests to MetricsServlet can make use of the following query-string
parameters:
/metrics?class=com.example.serviceclass is a string used to filter the metrics in the JSON by metric name. In
the given example, only metrics for classes whose canonical name starts with
com.example.service would be shown. You can also use jvm for
just the JVM-level metrics.
/metrics?pretty=truepretty determines whether or not the JSON which is returned is printed with
indented whitespace or not. If you're looking at the JSON in the browser, use this.
/metrics?full-samples=truefull-samples determines whether or not the JSON which is returned will
include the full content of histograms' and timers' reservoir samples. If you're
aggregating across hosts, you may want to do this to allow for more accurate quantile
calculations.
| Modifier and Type | Field and Description |
|---|---|
static String |
JSON_FACTORY_ATTRIBUTE
The attribute name of the
JsonFactory instance in the servlet context. |
static String |
REGISTRY_ATTRIBUTE
The attribute name of the
MetricsRegistry instance in the servlet context. |
static String |
SHOW_JVM_METRICS
The initialization parameter name which determines whether or not JVM_level metrics will be
included in the JSON output.
|
| Constructor and Description |
|---|
MetricsServlet()
Creates a new
MetricsServlet. |
MetricsServlet(boolean showJvmMetrics)
Creates a new
MetricsServlet. |
MetricsServlet(Clock clock,
VirtualMachineMetrics vm,
MetricsRegistry registry,
com.fasterxml.jackson.core.JsonFactory factory,
boolean showJvmMetrics)
Creates a new
MetricsServlet. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
void |
init(javax.servlet.ServletConfig config) |
void |
processCounter(MetricName name,
Counter counter,
com.yammer.metrics.reporting.MetricsServlet.Context context) |
void |
processGauge(MetricName name,
Gauge<?> gauge,
com.yammer.metrics.reporting.MetricsServlet.Context context) |
void |
processHistogram(MetricName name,
Histogram histogram,
com.yammer.metrics.reporting.MetricsServlet.Context context) |
void |
processMeter(MetricName name,
Metered meter,
com.yammer.metrics.reporting.MetricsServlet.Context context) |
void |
processTimer(MetricName name,
Timer timer,
com.yammer.metrics.reporting.MetricsServlet.Context context) |
void |
writeRegularMetrics(com.fasterxml.jackson.core.JsonGenerator json,
String classPrefix,
boolean showFullSamples) |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, servicepublic static final String REGISTRY_ATTRIBUTE
MetricsRegistry instance in the servlet context.public static final String JSON_FACTORY_ATTRIBUTE
JsonFactory instance in the servlet context.public static final String SHOW_JVM_METRICS
public MetricsServlet()
MetricsServlet.public MetricsServlet(boolean showJvmMetrics)
MetricsServlet.showJvmMetrics - whether or not JVM-level metrics will be included in the outputpublic MetricsServlet(Clock clock, VirtualMachineMetrics vm, MetricsRegistry registry, com.fasterxml.jackson.core.JsonFactory factory, boolean showJvmMetrics)
MetricsServlet.clock - the clock used for the current timevm - a VirtualMachineMetrics instanceregistry - a MetricsRegistryfactory - a JsonFactoryshowJvmMetrics - whether or not JVM-level metrics will be included in the outputpublic void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
init in interface javax.servlet.Servletinit in class javax.servlet.GenericServletjavax.servlet.ServletExceptionprotected void doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
throws javax.servlet.ServletException,
IOException
doGet in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionpublic void writeRegularMetrics(com.fasterxml.jackson.core.JsonGenerator json,
String classPrefix,
boolean showFullSamples)
throws IOException
IOExceptionpublic void processHistogram(MetricName name, Histogram histogram, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
processHistogram in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>Exceptionpublic void processCounter(MetricName name, Counter counter, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
processCounter in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>Exceptionpublic void processGauge(MetricName name, Gauge<?> gauge, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
processGauge in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>Exceptionpublic void processMeter(MetricName name, Metered meter, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
processMeter in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>Exceptionpublic void processTimer(MetricName name, Timer timer, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
processTimer in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>ExceptionCopyright © 2012. All Rights Reserved.