Java 类com.codahale.metrics.graphite.GraphiteUDP 实例源码

项目:graylog-plugin-metrics-reporter    文件:GraphiteSenderProvider.java   
@Override
public GraphiteSender get() {
    switch (configuration.getProtocol()) {
        case PICKLE:
            return new PickledGraphite(
                    configuration.getAddress(),
                    SocketFactory.getDefault(),
                    configuration.getCharset(),
                    configuration.getPickleBatchSize());
        case TCP:
            return new Graphite(configuration.getAddress(), SocketFactory.getDefault(), configuration.getCharset());
        case UDP:
            return new GraphiteUDP(configuration.getAddress());
        default:
            throw new IllegalArgumentException("Unknown Graphite protocol \"" + configuration.getProtocol() + "\"");
    }
}
项目:pay-adminusers    文件:AdminUsersApp.java   
private void initialiseMetrics(AdminUsersConfig configuration, Environment environment) {
    GraphiteSender graphiteUDP = new GraphiteUDP(configuration.getGraphiteHost(), Integer.valueOf(configuration.getGraphitePort()));
    GraphiteReporter.forRegistry(environment.metrics())
            .prefixedWith(SERVICE_METRICS_NODE)
            .build(graphiteUDP)
            .start(GRAPHITE_SENDING_PERIOD_SECONDS, TimeUnit.SECONDS);

}
项目:pay-cardid    文件:CardApi.java   
private void initialiseMetrics(CardConfiguration configuration, Environment environment) {
    GraphiteSender graphiteUDP = new GraphiteUDP(configuration.getGraphiteHost(), Integer.valueOf(configuration.getGraphitePort()));
    GraphiteReporter.forRegistry(environment.metrics())
            .prefixedWith(SERVICE_METRICS_NODE)
            .build(graphiteUDP)
            .start(GRAPHITE_SENDING_PERIOD_SECONDS, TimeUnit.SECONDS);

}
项目:graylog-plugin-metrics-reporter    文件:GraphiteSenderProviderTest.java   
@Test
public void getReturnsGraphiteUDP() throws Exception {
    final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() {
        @Override
        public GraphiteProtocol getProtocol() {
            return GraphiteProtocol.UDP;
        }
    };
    final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration);

    final GraphiteSender graphiteSender = provider.get();
    assertTrue(graphiteSender instanceof GraphiteUDP);
    assertFalse(graphiteSender.isConnected());
}
项目:graylog-plugin-metrics-reporter    文件:GraphiteReporterProviderTest.java   
@Test
public void get() throws Exception {
    final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration();
    final GraphiteSender graphiteSender = new GraphiteUDP("127.0.0.1", 12345);
    final MetricRegistry metricRegistry = new MetricRegistry();
    final GraphiteReporterProvider provider = new GraphiteReporterProvider(configuration, graphiteSender, metricRegistry);

    final GraphiteReporter reporter = provider.get();
    assertNotNull(reporter);
}
项目:Camel    文件:Application.java   
/**
 * 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;
}
项目:pay-publicauth    文件:PublicAuthApp.java   
private void initialiseMetrics(PublicAuthConfiguration configuration, Environment environment) {
    GraphiteSender graphiteUDP = new GraphiteUDP(configuration.getGraphiteHost(), Integer.valueOf(configuration.getGraphitePort()));
    GraphiteReporter.forRegistry(environment.metrics())
            .prefixedWith(SERVICE_METRICS_NODE)
            .build(graphiteUDP)
            .start(GRAPHITE_SENDING_PERIOD_SECONDS, TimeUnit.SECONDS);

}
项目:pay-publicapi    文件:PublicApi.java   
private void initialiseMetrics(PublicApiConfig configuration, Environment environment) {
    GraphiteSender graphiteUDP = new GraphiteUDP(configuration.getGraphiteHost(), Integer.valueOf(configuration.getGraphitePort()));
    GraphiteReporter.forRegistry(environment.metrics())
            .prefixedWith(SERVICE_METRICS_NODE)
            .build(graphiteUDP)
            .start(GRAPHITE_SENDING_PERIOD_SECONDS, TimeUnit.SECONDS);
}
项目:flink    文件:GraphiteReporter.java   
@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));
    }
}
项目:storm-graphite    文件:GraphiteReporter.java   
@Override public void prepare(Map<String, Object> conf) {
  if (conf.containsKey(GRAPHITE_HOST_OPTION)) {
    graphiteHost = (String) conf.get(GRAPHITE_HOST_OPTION);
  }
  else {
    throw new IllegalArgumentException("Field " + GRAPHITE_HOST_OPTION + " required.");
  }

  if (conf.containsKey(GRAPHITE_PORT_OPTION)) {
    graphitePort = Integer.parseInt((String) conf.get(GRAPHITE_PORT_OPTION));
  }
  else {
    throw new IllegalArgumentException("Field " + GRAPHITE_PORT_OPTION + " required.");
  }

  if (conf.containsKey(GRAPHITE_MIN_CONNECT_ATTEMPT_INTERVAL_SECS_OPTION)) {
    minConnectAttemptIntervalSecs = Integer
        .parseInt((String) conf.get(GRAPHITE_MIN_CONNECT_ATTEMPT_INTERVAL_SECS_OPTION));
  }
  else {
    minConnectAttemptIntervalSecs = DEFAULT_MIN_CONNECT_ATTEMPT_INTERVAL_SECS;
  }

  graphiteSocketAddr = new InetSocketAddress(graphiteHost, graphitePort);

  serverFingerprint = graphiteSocketAddr.getAddress() + ":" + graphiteSocketAddr.getPort();

  if (conf.containsKey(GRAPHITE_PROTOCOL_OPTION) && ((String)conf.get(GRAPHITE_PROTOCOL_OPTION)).equalsIgnoreCase("udp")) {
    // Use UDP client
    this.graphite = new GraphiteUDP(graphiteSocketAddr);
  } else {
    // Default TCP client
    int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
    if (conf.containsKey(GRAPHITE_CONNECT_TIMEOUT)) {
      connectTimeout = Integer.parseInt(conf.get(GRAPHITE_CONNECT_TIMEOUT).toString());
    }

    int readTimeout = DEFAULT_READ_TIMEOUT;
    if (conf.containsKey(GRAPHITE_READ_TIMEOUT)) {
      readTimeout = Integer.parseInt(conf.get(GRAPHITE_READ_TIMEOUT).toString());
    }

    ConfigurableSocketFactory socketFactory = new ConfigurableSocketFactory();
    socketFactory.setConnectTimeout(connectTimeout);
    socketFactory.setReadTimeout(readTimeout);

    this.graphite = new Graphite(graphiteSocketAddr, socketFactory);
  }
  lastConnectAttemptTimestampMs = 0;
  prefix = TagsHelper.getPrefix(conf);
}