use of com.codahale.metrics.graphite.GraphiteUDP in project dropwizard by dropwizard.
the class GraphiteReporterFactoryTest method testCorrectTransportForGraphiteUDP.
@Test
void testCorrectTransportForGraphiteUDP() throws Exception {
graphiteReporterFactory.setTransport("udp");
graphiteReporterFactory.build(new MetricRegistry());
final ArgumentCaptor<GraphiteUDP> argument = ArgumentCaptor.forClass(GraphiteUDP.class);
verify(builderSpy).build(argument.capture());
final GraphiteUDP graphite = argument.getValue();
final FieldAccessor<GraphiteUDP> graphiteUDPFieldAccessor = new FieldAccessor<>(graphite);
assertThat(graphiteUDPFieldAccessor.getField("hostname")).isEqualTo("localhost");
assertThat(graphiteUDPFieldAccessor.getField("port")).isEqualTo(2003);
assertThat(graphiteUDPFieldAccessor.getField("address")).isNull();
}
use of com.codahale.metrics.graphite.GraphiteUDP 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.GraphiteUDP in project storm by apache.
the class GraphiteStormReporter method prepare.
@Override
public void prepare(MetricRegistry metricsRegistry, Map<String, Object> topoConf, Map<String, Object> reporterConf) {
LOG.debug("Preparing...");
GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metricsRegistry);
TimeUnit durationUnit = ClientMetricsUtils.getMetricsDurationUnit(reporterConf);
if (durationUnit != null) {
builder.convertDurationsTo(durationUnit);
}
TimeUnit rateUnit = ClientMetricsUtils.getMetricsRateUnit(reporterConf);
if (rateUnit != null) {
builder.convertRatesTo(rateUnit);
}
StormMetricsFilter filter = getMetricsFilter(reporterConf);
if (filter != null) {
builder.filter(filter);
}
String prefix = getMetricsPrefixedWith(reporterConf);
if (prefix != null) {
builder.prefixedWith(prefix);
}
// defaults to 10
reportingPeriod = getReportPeriod(reporterConf);
// defaults to seconds
reportingPeriodUnit = getReportPeriodUnit(reporterConf);
// Not exposed:
// * withClock(Clock)
String host = getMetricsTargetHost(reporterConf);
Integer port = getMetricsTargetPort(reporterConf);
String transport = getMetricsTargetTransport(reporterConf);
GraphiteSender sender = null;
if (transport.equalsIgnoreCase("udp")) {
sender = new GraphiteUDP(host, port);
} else {
sender = new Graphite(host, port);
}
reporter = builder.build(sender);
}
use of com.codahale.metrics.graphite.GraphiteUDP in project flink by apache.
the class GraphiteReporter method getReporter.
@Override
public ScheduledReporter getReporter(MetricConfig config) {
String host = config.getString(ARG_HOST, null);
int port = config.getInteger(ARG_PORT, -1);
if (host == null || host.length() == 0 || port < 1) {
throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
}
String prefix = config.getString(ARG_PREFIX, null);
String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
String protocol = config.getString(ARG_PROTOCOL, "TCP");
com.codahale.metrics.graphite.GraphiteReporter.Builder builder = com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);
if (prefix != null) {
builder.prefixedWith(prefix);
}
if (conversionRate != null) {
builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
}
if (conversionDuration != null) {
builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
}
Protocol prot;
try {
prot = Protocol.valueOf(protocol);
} catch (IllegalArgumentException iae) {
log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
prot = Protocol.TCP;
}
log.info("Configured GraphiteReporter with {host:{}, port:{}, protocol:{}}", host, port, prot);
switch(prot) {
case UDP:
return builder.build(new GraphiteUDP(host, port));
case TCP:
default:
return builder.build(new Graphite(host, port));
}
}
Aggregations