Help needed to use com.codahale.metrics.servlet.InstrumentedFilter

507 views
Skip to first unread message

arun kumar

unread,
Apr 1, 2016, 6:38:12 AM4/1/16
to metrics-user
I have done as per the documentation https://dropwizard.github.io/metrics/3.1.0/manual/servlet/

public class TxnMetrics extends InstrumentedFilterContextListener{
    public static final MetricRegistry metrics = new MetricRegistry();
 
 @Override
    protected MetricRegistry getMetricRegistry() {
        System.out.println("INFO : Flow reached getMetricRegistry() ");
         return metrics;
    }

Here is my web.xml
<filter>
    <filter-name>instrumentedFilter</filter-name>
    <filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
   </filter>
<filter-mapping>
    <filter-name>instrumentedFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

My metricsRegistry is not injected into servlet context.
I have configured console reporter, It is not showing while my application gets hit.
Am i missing soming ? Please clarify me. Thanks in advance.

Thamizh Arasu

unread,
Apr 24, 2016, 7:39:20 AM4/24/16
to metrics-user
I have also tried similar for ConsoleReporter and it is working fine for me. But I tried this with Jersey REST service. I have written an article on this also http://cloudskol.com/index.php/2016/04/24/restful-java-metering-dropwizard-metrics/

May be helpful to you.

I have already filed an issue in Github regarding MetricServlet is NOT working...

Jens

unread,
Apr 26, 2016, 7:53:35 AM4/26/16
to metrics-user
You have to register your TxnMetrics context listener through your web.xml.

<listener>
 
<listener-class>com.example.TxnMetrics</listener-class>
</listener>

If you use servlet 3.x you could also annotate the class using @WebListener instead so it gets automatically registered.


-- J.
Reply all
Reply to author
Forward
0 new messages