public static void enable(long period, TimeUnit unit, String apiKey, String host) { DatadogReporter dd = new DatadogReporter(Metrics.defaultRegistry(), apiKey, host); dd.start(period, unit); }
public static void enable(long period, TimeUnit unit, String apiKey) { enable(period, unit, apiKey, null); }
public void processTimer(MetricName name, Timer timer, Long epoch) throws Exception { processMeter(name, timer, epoch); pushSummarizable(name, timer, epoch); pushSampling(name, timer, epoch); }
public void processHistogram(MetricName name, Histogram histogram, Long epoch) throws Exception { pushSummarizable(name, histogram, epoch); pushSampling(name, histogram, epoch); }
private void pushCounter(MetricName metricName, Long count, Long epoch, String... path) { pushCounter(sanitizeName(metricName, path), count, epoch); }
protected void pushVmMetrics(long epoch) { sendGauge("jvm.memory.heap_usage", vm.heapUsage(), epoch); sendGauge("jvm.memory.non_heap_usage", vm.nonHeapUsage(), epoch); for (Entry<String, Double> pool : vm.memoryPoolUsage().entrySet()) { String gaugeName = String.format("jvm.memory.memory_pool_usage[pool:%s]", pool.getKey()); sendGauge(gaugeName, pool.getValue(), epoch); } pushGauge("jvm.daemon_thread_count", vm.daemonThreadCount(), epoch); pushGauge("jvm.thread_count", vm.threadCount(), epoch); pushCounter("jvm.uptime", vm.uptime(), epoch); sendGauge("jvm.fd_usage", vm.fileDescriptorUsage(), epoch); for (Entry<Thread.State, Double> entry : vm.threadStatePercentages() .entrySet()) { String gaugeName = String.format("jvm.thread-states[state:%s]", entry.getKey()); sendGauge(gaugeName, entry.getValue(), epoch); } for (Entry<String, VirtualMachineMetrics.GarbageCollectorStats> entry : vm .garbageCollectors().entrySet()) { pushGauge("jvm.gc.time", entry.getValue().getTime(TimeUnit.MILLISECONDS), epoch); pushCounter("jvm.gc.runs", entry.getValue().getRuns(), epoch); } }
public void processMeter(MetricName name, Metered meter, Long epoch) throws Exception { pushCounter(name, meter.count(), epoch); pushGauge(name, meter.meanRate(), epoch, "mean"); pushGauge(name, meter.oneMinuteRate(), epoch, "1MinuteRate"); pushGauge(name, meter.fiveMinuteRate(), epoch, "5MinuteRate"); pushGauge(name, meter.fifteenMinuteRate(), epoch, "15MinuteRate"); }
@Override public void run() { Request request = null; try { request = transport.prepare(); jsonOut = jsonFactory.createJsonGenerator(request.getBodyWriter()); jsonOut.writeStartObject(); jsonOut.writeFieldName("series"); jsonOut.writeStartArray(); } catch (IOException ioe) { LOG.error("Could not prepare request", ioe); return; } final long epoch = clock.time() / 1000; if (this.printVmMetrics) { pushVmMetrics(epoch); } pushRegularMetrics(epoch); try { jsonOut.writeEndArray(); jsonOut.writeEndObject(); jsonOut.flush(); request.send(); } catch (Exception e) { LOG.error("Error sending metrics", e); } }
private void pushSummarizable(MetricName name, Summarizable summarizable, Long epoch) { pushGauge(name, summarizable.min(), epoch, "min"); pushGauge(name, summarizable.max(), epoch, "max"); pushGauge(name, summarizable.mean(), epoch, "mean"); pushGauge(name, summarizable.stdDev(), epoch, "stddev"); }
public void processCounter(MetricName name, Counter counter, Long epoch) throws Exception { pushCounter(name, counter.count(), epoch); }
protected void pushRegularMetrics(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 e) { LOG.error("Error pushing metric", e); } } } } }
public void processGauge(MetricName name, Gauge<?> gauge, Long epoch) throws Exception { pushGauge(name, (Number) gauge.value(), epoch); }
public static void enableForEc2Instance(long period, TimeUnit unit, String apiKey) throws IOException { String hostName = AwsHelper.getEc2InstanceId(); DatadogReporter dd = new DatadogReporter(Metrics.defaultRegistry(), apiKey, hostName); dd.start(period, unit); }
private void pushSampling(MetricName name, Sampling sampling, Long epoch) { final Snapshot snapshot = sampling.getSnapshot(); pushGauge(name, snapshot.getMedian(), epoch, "median"); pushGauge(name, snapshot.get75thPercentile(), epoch, "75percentile"); pushGauge(name, snapshot.get95thPercentile(), epoch, "95percentile"); pushGauge(name, snapshot.get98thPercentile(), epoch, "98percentile"); pushGauge(name, snapshot.get99thPercentile(), epoch, "99percentile"); pushGauge(name, snapshot.get999thPercentile(), epoch, "999percentile"); }