Search in sources :

Example 1 with GraphiteUDP

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();
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP) Test(org.junit.jupiter.api.Test)

Example 2 with GraphiteUDP

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;
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP) Bean(org.springframework.context.annotation.Bean)

Example 3 with GraphiteUDP

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);
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Graphite(com.codahale.metrics.graphite.Graphite) TimeUnit(java.util.concurrent.TimeUnit) StormMetricsFilter(org.apache.storm.metrics2.filters.StormMetricsFilter) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP)

Example 4 with GraphiteUDP

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));
    }
}
Also used : Graphite(com.codahale.metrics.graphite.Graphite) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP)

Aggregations

GraphiteUDP (com.codahale.metrics.graphite.GraphiteUDP)4 Graphite (com.codahale.metrics.graphite.Graphite)2 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)2 GraphiteSender (com.codahale.metrics.graphite.GraphiteSender)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 InetSocketAddress (java.net.InetSocketAddress)1 TimeUnit (java.util.concurrent.TimeUnit)1 StormMetricsFilter (org.apache.storm.metrics2.filters.StormMetricsFilter)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1