use of com.codahale.metrics.graphite.GraphiteSender in project ninja by ninjaframework.
the class NinjaGraphite method start.
@Start(order = 90)
public void start() {
if (ninjaProperties.getBooleanWithDefault("metrics.graphite.enabled", false)) {
final String hostname = metricsService.getHostname();
final String address = ninjaProperties.getOrDie("metrics.graphite.address");
final int port = ninjaProperties.getIntegerWithDefault("metrics.graphite.port", 2003);
final boolean isPickled = ninjaProperties.getBooleanWithDefault("metrics.graphite.pickled", false);
final String period = ninjaProperties.getWithDefault("metrics.graphite.period", "60s");
final int delay = TimeUtil.parseDuration(period);
final InetSocketAddress graphiteAddress = new InetSocketAddress(address, port);
final GraphiteSender sender;
if (isPickled) {
sender = new PickledGraphite(graphiteAddress);
} else {
sender = new Graphite(graphiteAddress);
}
reporter = GraphiteReporter.forRegistry(metricsService.getMetricRegistry()).prefixedWith(hostname).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(sender);
reporter.start(delay, TimeUnit.SECONDS);
log.info("Started Graphite Metrics reporter for '{}', updating every {}", hostname, period);
}
}
use of com.codahale.metrics.graphite.GraphiteSender in project camel by apache.
the class Application method graphiteReporter.
/**
* Create reporter bean and tell Spring to call stop() when shutting down.
* UPD must be enabled in carbon.conf
*
* @return graphite reporter
*/
@Bean(destroyMethod = "stop")
public GraphiteReporter graphiteReporter() {
final GraphiteSender graphite = new GraphiteUDP(new InetSocketAddress("localhost", 2003));
final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry).prefixedWith("camel-spring-boot").convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
reporter.start(5, TimeUnit.SECONDS);
return reporter;
}
use of com.codahale.metrics.graphite.GraphiteSender in project lucene-solr by apache.
the class SolrGraphiteReporter method validate.
@Override
protected void validate() throws IllegalStateException {
if (!enabled) {
log.info("Reporter disabled for registry " + registryName);
return;
}
if (host == null) {
throw new IllegalStateException("Init argument 'host' must be set to a valid Graphite server name.");
}
if (port == -1) {
throw new IllegalStateException("Init argument 'port' must be set to a valid Graphite server port.");
}
if (reporter != null) {
throw new IllegalStateException("Already started once?");
}
if (period < 1) {
throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
}
GraphiteSender graphite;
String id = host + ":" + port + ":" + pickled;
graphite = serviceRegistry.getOrCreate(id, () -> {
if (pickled) {
return new PickledGraphite(host, port);
} else {
return new Graphite(host, port);
}
});
if (instancePrefix == null) {
instancePrefix = registryName;
} else {
instancePrefix = instancePrefix + "." + registryName;
}
GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metricManager.registry(registryName)).prefixedWith(instancePrefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS);
MetricFilter filter;
if (!filters.isEmpty()) {
filter = new SolrMetricManager.PrefixFilter(filters);
} else {
filter = MetricFilter.ALL;
}
builder = builder.filter(filter);
reporter = builder.build(graphite);
reporter.start(period, TimeUnit.SECONDS);
}
Aggregations