jerseydropwizardmetricsgraphitecodahale-metrics

Dropwizard metrics in Graphite


we have multiple API endpoints created with Jersey with a web.xml setup rather than the resource config setup. We want to capture and display metrics for all requests for each endpoint including all of the different response codes. So far I have create a class that extends the InstrumentedFilterContextListener and has the Graphite reporter in it.

In the web.xml I have added the following blocks to get the reporting working:

<listener>
    <listener-class>metrics.MyInstrumentedFilterContextListener</listener-class>
</listener>


<filter>
    <filter-name>testFilter</filter-name>
    <filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
    <init-param>
        <param-name>name-prefix</param-name>
        <param-value>testEndpoint</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>testFilter</filter-name>
    <url-pattern>/api/testEP1/*</url-pattern>
</filter-mapping>
enter code here

<filter>
    <filter-name>testFilter2</filter-name>
    <filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
    <init-param>
        <param-name>name-prefix</param-name>
        <param-value>testEndpoint2</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>testFilter2</filter-name>
    <url-pattern>/api/testEP2/*</url-pattern>
</filter-mapping>

So with the above config and the class below I am getting some information in the Graphite Dashboard:

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

static {

    final Graphite graphite = new Graphite(new InetSocketAddress("localhost", 8080));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(METRIC_REGISTRY)
            .prefixedWith("API.Metrics")
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)

            .build(graphite);
    reporter.start(10, TimeUnit.SECONDS);
}

@Override
protected MetricRegistry getMetricRegistry() {
    return METRIC_REGISTRY;
}
}

My issue at the minute is that from what I can tell it is mostly machine related metrics, cpu, memory etc., that are being captured and not things like the number of ok, error or not found requests for the endpoints I have mapped. I have tested that the requests are being captured by my listener class by adding a ConsoleReporter too so that I could see all of the counts for the different requests increasing. So my question, finally, is how do I see all of the same Meter and Timer data in Graphite? Are there some extra settings I have to set or something to get this data or is the data just called something completely different in Graphite?


Solution

  • The issue was that the socket specified in this line was incorrect but the only way to find the socket was to use netstat and it ended up being 22033 in my case:

    final Graphite graphite = new Graphite(new InetSocketAddress("localhost", 8080));
    

    This might have been specified in some file within graphite but i did not find it mentioned in any documentation.