@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() + "\""); } }
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); }
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); }
private static void initGraphiteReporter(final GraphiteReporterConfig graphiteReporterConfig) { HostAndPort hostAndPort = graphiteReporterConfig.getAddress(); InetSocketAddress inetSocketAddress = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); GraphiteSender graphiteSender = graphiteReporterConfig.isEnableBatching() ? new PickledGraphite(inetSocketAddress) : new Graphite(inetSocketAddress); graphiteReporter = GraphiteReporter.forRegistry(metricRegistry) .prefixedWith(prefix) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MICROSECONDS) .withClock(new Clock() { private long lastReportingTime = 0; @Override public long getTick() { return System.nanoTime(); } @Override public synchronized long getTime() { if (lastReportingTime == 0) { lastReportingTime = System.currentTimeMillis(); return lastReportingTime; } lastReportingTime += graphiteReporterConfig.getReportingIntervalInSeconds() * 1000; return lastReportingTime; } }) .filter(buildMetricFilter(graphiteReporterConfig.getStartsWithFilters(), graphiteReporterConfig.getBlockedStartsWithFilters())) .build(graphiteSender); graphiteReporter.start(graphiteReporterConfig.getReportingIntervalInSeconds(), TimeUnit.SECONDS); }
@Override protected void configure() { bind(GraphiteSender.class).toProvider(GraphiteSenderProvider.class); bind(GraphiteReporter.class).toProvider(GraphiteReporterProvider.class); addConfigBeans(); addInitializer(MetricsGraphiteReporterService.class); }
@Inject public GraphiteReporterProvider(MetricsGraphiteReporterConfiguration configuration, GraphiteSender graphiteSender, MetricRegistry metricRegistry) { this.configuration = requireNonNull(configuration); this.graphiteSender = requireNonNull(graphiteSender); this.metricRegistry = requireNonNull(metricRegistry); }
@Test public void getReturnsGraphite() throws Exception { final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() { @Override public GraphiteProtocol getProtocol() { return GraphiteProtocol.TCP; } }; final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration); final GraphiteSender graphiteSender = provider.get(); assertTrue(graphiteSender instanceof Graphite); assertFalse(graphiteSender.isConnected()); }
@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()); }
@Test public void getReturnsGraphitePickledGraphite() throws Exception { final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() { @Override public GraphiteProtocol getProtocol() { return GraphiteProtocol.PICKLE; } }; final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration); final GraphiteSender graphiteSender = provider.get(); assertTrue(graphiteSender instanceof PickledGraphite); assertFalse(graphiteSender.isConnected()); }
@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); }
@Bean(destroyMethod = "stop") public GraphiteReporter graphiteReporter() { GraphiteSender sender = new Graphite("localhost", 2003); GraphiteReporter reporter = GraphiteReporter.forRegistry(registry).prefixedWith("user-service").convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(sender); reporter.start(10, TimeUnit.SECONDS); return reporter; }
/** * 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; }
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); }
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); }
GraphiteMetricSender(GraphiteSender graphite, Clock clock, String prefix) { this.graphite = graphite; this.clock = clock; this.prefix = prefix; }
protected GraphiteReporter(MetricContext context, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, GraphiteSender graphiteSender) { super(context, name, filter, rateUnit, durationUnit); this.graphiteSender = graphiteSender; }
public Builder(String name, GraphiteSender graphiteSender) { super(name); this.graphiteSender = graphiteSender; }
public FilteringGraphiteSender(GraphiteSender delegate, Predicate<String> predicate) { this.delegate = delegate; this.predicate = predicate; }
private GraphiteSender graphiteSender(final MetricsProperties.Graphite graphiteMetricsProperties, final Predicate<String> graphiteFilterPredicate) { final InetSocketAddress address = new InetSocketAddress(graphiteMetricsProperties.getHost(), valueOf(graphiteMetricsProperties.getPort())); return new FilteringGraphiteSender(new Graphite(address), graphiteFilterPredicate); }
private void sendValue(String name, GraphiteSender delegate) throws IOException { new FilteringGraphiteSender(delegate, predicate).send(name, value, timestamp); }
/** * Create a new {@link gobblin.metrics.graphite.GraphiteReporter.Builder} that uses * the simple name of {@link GraphiteReporter} as the reporter name. * * @param graphiteSender a {@link com.codahale.metrics.graphite.GraphiteSender} to * send metrics to Graphite * @return a new {@link gobblin.metrics.graphite.GraphiteReporter.Builder} */ public static Builder builder(GraphiteSender graphiteSender) { return builder(GraphiteReporter.class.getName(), graphiteSender); }
/** * Create a new {@link gobblin.metrics.graphite.GraphiteReporter.Builder} that uses * a given reporter name. * * @param name the given reporter name * @param graphiteSender a {@link com.codahale.metrics.graphite.GraphiteSender} * to send metrics to Graphite * @return a new {@link gobblin.metrics.graphite.GraphiteReporter.Builder} */ public static Builder builder(String name, GraphiteSender graphiteSender) { return new Builder(name, graphiteSender); }