Search code examples
javajmxmetricsgraphitecodahale-metrics

Displaying Java Metrics results in Graphite


I have setup a Graphite server and I am trying to print my Java metrics into the graphite UI. Graphite is up and running as I can see its web UI in localhost. I used the below code to redirect my metrics results to graphite console.

Graphite graphite = new Graphite(new InetSocketAddress("http://localhost", 80));
    GraphiteReporter reporter = GraphiteReporter.forRegistry(this.metricRegistry)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);
    reporter.start(1, TimeUnit.MINUTES);

But nothing appears on the web UI. What am I doing wrong here? Do I need to specify any additional configuration for graphite? After installing graphite, I didn't add any configurations.Any help would be much appreciated.


Solution

  • The InetSocketAddress you've created points to localhost on port 80. Are you running carbon locally on that port? Normally the web interface will be running behind Apache or nginx on port 80 and the carbon-cache process (which actually receives the metrics from the GraphiteReporter) will run on port 2003.

    In a standard set-up it should just be a case of switch port 80 with 2003 in your InetSocketAddress constructor.