Skip to content

Instantly share code, notes, and snippets.

@yinjae
Created May 23, 2016 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yinjae/801096cd2564ef9605f7e808c19a5abf to your computer and use it in GitHub Desktop.
Save yinjae/801096cd2564ef9605f7e808c19a5abf to your computer and use it in GitHub Desktop.
graphite reporter
GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry())
.prefixedWith(getHostname()).convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.filter((name, metric) -> !name.toLowerCase().contains("servo"))
.build(new Graphite(new InetSocketAddress("sv-graphite.idincu.net", 2003)));
reporter.start(1, TimeUnit.MINUTES);
private MetricRegistry metricRegistry() {
MetricRegistry registry = new MetricRegistry();
registry.register("custom.gc", new GarbageCollectorMetricSet());
registry.register("custom.class", new ClassLoadingGaugeSet());
registry.register("custom.file", new FileDescriptorRatioGauge());
registry.register("custom.memory", new MemoryUsageGaugeSet());
registry.register("custom.thread.status", new ThreadStatesGaugeSet());
return registry;
}
private String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
return "unknownHost";
}
}
build.gradle
compile group: 'io.dropwizard.metrics', name: 'metrics-jvm', version: '3.1.2'
compile 'io.dropwizard.metrics:metrics-graphite:3.1.2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment