Fork me on GitHub

Instrumenting Web Applications

The metrics-servlet module provides a Servlet filter which has meters for status codes, a counter for the number of active requests, and a timer for request duration. You can use it in your web.xml like this:


You will need to add your MetricRegistry to the servlet context as an attribute named com.codahale.metrics.servlet.InstrumentedFilter.registry. You can do this using the Servlet API by extending InstrumentedFilterContextListener:

public class MyInstrumentedFilterContextListener extends InstrumentedFilterContextListener {
    public static final MetricRegistry REGISTRY = new MetricRegistry();

    protected MetricRegistry getMetricRegistry() {
        return REGISTRY;