/** * Enables the graphite reporter to send data to graphite server with the specified period. * * @param metricsRegistry the metrics registry * @param period the period between successive outputs * @param unit the time unit of {@code period} * @param host the host name of graphite server (carbon-cache agent) * @param port the port number on which the graphite server is listening * @param prefix the string which is prepended to all metric names * @param predicate filters metrics to be reported */ public static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port, String prefix, MetricPredicate predicate) { try { final GraphiteReporter reporter = new GraphiteReporter(metricsRegistry, prefix, predicate, new DefaultSocketProvider(host, port), Clock.defaultClock()); reporter.start(period, unit); } catch (Exception e) { LOG.error("Error creating/starting Graphite reporter:", e); } }
private FilteredGraphiteReporter buildGraphiteReporter() { FilteredGraphiteReporter graphiteReporter = null; try { graphiteReporter = new FilteredGraphiteReporter( Metrics.defaultRegistry(), metricPrefix, metricPredicate, metricDimensions, new FilteredGraphiteReporter.DefaultSocketProvider(graphiteHost, graphitePort), Clock.defaultClock() ); } catch (IOException e) { LOG.error("Unable to initialize GraphiteReporter", e); } return graphiteReporter; } }
/** * Creates a new {@link GraphiteReporter}. * * @param metricsRegistry the metrics registry * @param host is graphite server * @param port is port on which graphite server is running * @param prefix is prepended to all names reported to graphite * @throws IOException if there is an error connecting to the Graphite server */ public GraphiteReporter(MetricsRegistry metricsRegistry, String host, int port, String prefix) throws IOException { this(metricsRegistry, prefix, MetricPredicate.ALL, new DefaultSocketProvider(host, port), Clock.defaultClock()); }