/** * Enables the graphite reporter to send data for the given metrics registry 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 */ public static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port) { enable(metricsRegistry, period, unit, host, port, null); }
@Override public void processTimer(MetricName name, Timer timer, Long epoch) throws IOException { processMeter(name, timer, epoch); final String sanitizedName = sanitizeName(name); sendSummarizable(epoch, sanitizedName, timer); sendSampling(epoch, sanitizedName, timer); }
@Override public void processHistogram(MetricName name, Histogram histogram, Long epoch) throws IOException { final String sanitizedName = sanitizeName(name); sendSummarizable(epoch, sanitizedName, histogram); sendSampling(epoch, sanitizedName, histogram); }
@Override public void processGauge(MetricName name, Gauge<?> gauge, Long epoch) throws IOException { sendObjToGraphite(epoch, sanitizeName(name), "value", gauge.value()); }
/** * 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); } }
@Override public void processMeter(MetricName name, Metered meter, Long epoch) throws IOException { final String sanitizedName = sanitizeName(name); sendInt(epoch, sanitizedName, "count", meter.count()); sendFloat(epoch, sanitizedName, "meanRate", meter.meanRate()); sendFloat(epoch, sanitizedName, "1MinuteRate", meter.oneMinuteRate()); sendFloat(epoch, sanitizedName, "5MinuteRate", meter.fiveMinuteRate()); sendFloat(epoch, sanitizedName, "15MinuteRate", meter.fifteenMinuteRate()); }
protected void printVmMetrics(long epoch) { sendFloat(epoch, "jvm.memory", "heap_usage", vm.heapUsage()); sendFloat(epoch, "jvm.memory", "non_heap_usage", vm.nonHeapUsage()); for (Entry<String, Double> pool : vm.memoryPoolUsage().entrySet()) { sendFloat(epoch, "jvm.memory.memory_pool_usages", sanitizeString(pool.getKey()), pool.getValue()); } sendInt(epoch, "jvm", "daemon_thread_count", vm.daemonThreadCount()); sendInt(epoch, "jvm", "thread_count", vm.threadCount()); sendInt(epoch, "jvm", "uptime", vm.uptime()); sendFloat(epoch, "jvm", "fd_usage", vm.fileDescriptorUsage()); for (Entry<State, Double> entry : vm.threadStatePercentages().entrySet()) { sendFloat(epoch, "jvm.thread-states", entry.getKey().toString().toLowerCase(), entry.getValue()); } for (Entry<String, VirtualMachineMetrics.GarbageCollectorStats> entry : vm.garbageCollectors().entrySet()) { final String name = "jvm.gc." + sanitizeString(entry.getKey()); sendInt(epoch, name, "time", entry.getValue().getTime(TimeUnit.MILLISECONDS)); sendInt(epoch, name, "runs", entry.getValue().getRuns()); } }
@Override public void processCounter(MetricName name, Counter counter, Long epoch) throws IOException { sendInt(epoch, sanitizeName(name), "count", counter.count()); }
printVmMetrics(epoch); printRegularMetrics(epoch); writer.flush(); } catch (Exception e) {
protected void sendToGraphite(long timestamp, String name, String value) { try { if (!prefix.isEmpty()) { writer.write(prefix); } writer.write(sanitizeString(name)); writer.write('.'); writer.write(value); writer.write(' '); writer.write(Long.toString(timestamp)); writer.write('\n'); writer.flush(); } catch (IOException e) { LOG.error("Error sending to Graphite:", e); } }
protected void printRegularMetrics(final Long epoch) { for (Entry<String,SortedMap<MetricName,Metric>> entry : getMetricsRegistry().groupedMetrics( predicate).entrySet()) { for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception ignored) { LOG.error("Error printing regular metrics:", ignored); } } } } }
GraphiteReporter graphiteReporter = new GraphiteReporter(graphiteHost, Integer.parseInt(graphitePort), StringUtils.trimToNull(graphitePrefix)); graphiteReporter.printVMMetrics = !disableJvmMetrics; graphiteReporter.start(reportingInterval, TimeUnit.SECONDS); reportingEnabled = true;
/** * 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 */ public static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port, String prefix) { enable(metricsRegistry, period, unit, host, port, prefix, MetricPredicate.ALL); }
/** * Enables the graphite reporter to send data for the default metrics registry to graphite * server with the specified period. * * @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 */ public static void enable(long period, TimeUnit unit, String host, int port) { enable(Metrics.defaultRegistry(), period, unit, host, port); }
/** * Enables the graphite reporter to send data to graphite server with the specified period. * * @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 */ public static void enable(long period, TimeUnit unit, String host, int port, String prefix) { enable(Metrics.defaultRegistry(), period, unit, host, port, prefix); }
com.yammer.metrics.reporting.GraphiteReporter.enable(Metrics.defaultRegistry(), getPeriod(), getRealTimeunit(), hostPort.getHost(), hostPort.getPort(), getResolvedPrefix(), getMetricPredicate());
private void enableMetrics2(HostPort hostPort) { GraphiteReporter.enable( Metrics.defaultRegistry(), getPeriod(), getRealTimeunit(), hostPort.getHost(), hostPort.getPort(), getResolvedPrefix(), MetricPredicateTransformer.generatePredicate(getPredicate())); }