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.service
class
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=true
pretty
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=true
full-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)
Process the given counter.
|
void |
processGauge(MetricName name,
Gauge<?> gauge,
com.yammer.metrics.reporting.MetricsServlet.Context context)
Process the given gauge.
|
void |
processHistogram(MetricName name,
Histogram histogram,
com.yammer.metrics.reporting.MetricsServlet.Context context)
Process the given histogram.
|
void |
processMeter(MetricName name,
Metered meter,
com.yammer.metrics.reporting.MetricsServlet.Context context)
Process the given
Metered instance. |
void |
processTimer(MetricName name,
Timer timer,
com.yammer.metrics.reporting.MetricsServlet.Context context)
Process the given timer.
|
void |
writeRegularMetrics(com.fasterxml.jackson.core.JsonGenerator json,
String classPrefix,
boolean showFullSamples) |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
public 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 MetricsRegistry
factory
- a JsonFactory
showJvmMetrics
- 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.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
public void writeRegularMetrics(com.fasterxml.jackson.core.JsonGenerator json, String classPrefix, boolean showFullSamples) throws IOException
IOException
public void processHistogram(MetricName name, Histogram histogram, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
MetricProcessor
processHistogram
in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
name
- the name of the histogramhistogram
- the histogramcontext
- the context of the meterException
- if something goes wrongpublic void processCounter(MetricName name, Counter counter, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
MetricProcessor
processCounter
in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
name
- the name of the countercounter
- the countercontext
- the context of the meterException
- if something goes wrongpublic void processGauge(MetricName name, Gauge<?> gauge, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
MetricProcessor
processGauge
in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
name
- the name of the gaugegauge
- the gaugecontext
- the context of the meterException
- if something goes wrongpublic void processMeter(MetricName name, Metered meter, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
MetricProcessor
Metered
instance.processMeter
in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
name
- the name of the metermeter
- the metercontext
- the context of the meterException
- if something goes wrongpublic void processTimer(MetricName name, Timer timer, com.yammer.metrics.reporting.MetricsServlet.Context context) throws Exception
MetricProcessor
processTimer
in interface MetricProcessor<com.yammer.metrics.reporting.MetricsServlet.Context>
name
- the name of the timertimer
- the timercontext
- the context of the meterException
- if something goes wrongCopyright © 2014. All Rights Reserved.