List of usage examples for org.apache.hadoop.metrics2 MetricsRecordBuilder addCounter
public abstract MetricsRecordBuilder addCounter(MetricsInfo info, long value);
From source file:com.github.joshelser.dropwizard.metrics.hadoop.HadoopMetrics2Reporter.java
License:Apache License
/** * Consumes the current metrics collected by dropwizard and adds them to the {@code builder}. * * @param builder A record builder// ww w . j a va2s. c o m */ void snapshotAllMetrics(MetricsRecordBuilder builder) { try { // Pass through the gauges @SuppressWarnings("rawtypes") Iterator<Entry<String, Gauge>> gaugeIterator = dropwizardGauges.entrySet().iterator(); while (gaugeIterator.hasNext()) { @SuppressWarnings("rawtypes") Entry<String, Gauge> gauge = gaugeIterator.next(); final MetricsInfo info = Interns.info(gauge.getKey(), EMPTY_STRING); final Object o = gauge.getValue().getValue(); // Figure out which gauge types metrics2 supports and call the right method if (o instanceof Integer) { builder.addGauge(info, (int) o); } else if (o instanceof Long) { builder.addGauge(info, (long) o); } else if (o instanceof Float) { builder.addGauge(info, (float) o); } else if (o instanceof Double) { builder.addGauge(info, (double) o); } else { LOG.trace("Ignoring Gauge ({}) with unhandled type: {}", gauge.getKey(), o.getClass()); } } } finally { dropwizardGauges = EMPTY_GAUGE_MAP; } try { // Pass through the counters Iterator<Entry<String, Counter>> counterIterator = dropwizardCounters.entrySet().iterator(); while (counterIterator.hasNext()) { Entry<String, Counter> counter = counterIterator.next(); MetricsInfo info = Interns.info(counter.getKey(), EMPTY_STRING); builder.addCounter(info, counter.getValue().getCount()); } } finally { dropwizardCounters = EMPTY_COUNTER_MAP; } try { // Pass through the histograms Iterator<Entry<String, Histogram>> histogramIterator = dropwizardHistograms.entrySet().iterator(); while (histogramIterator.hasNext()) { final Entry<String, Histogram> entry = histogramIterator.next(); final String name = entry.getKey(); final Histogram histogram = entry.getValue(); addSnapshot(builder, name, EMPTY_STRING, histogram.getSnapshot(), histogram.getCount()); } } finally { dropwizardHistograms = EMPTY_HISTOGRAM_MAP; } try { // Pass through the meter values Iterator<Entry<String, Meter>> meterIterator = dropwizardMeters.entrySet().iterator(); while (meterIterator.hasNext()) { final Entry<String, Meter> meterEntry = meterIterator.next(); final String name = meterEntry.getKey(); final Meter meter = meterEntry.getValue(); addMeter(builder, name, EMPTY_STRING, meter.getCount(), meter.getMeanRate(), meter.getOneMinuteRate(), meter.getFiveMinuteRate(), meter.getFifteenMinuteRate()); } } finally { dropwizardMeters = EMPTY_METER_MAP; } try { // Pass through the timers (meter + histogram) Iterator<Entry<String, Timer>> timerIterator = dropwizardTimers.entrySet().iterator(); while (timerIterator.hasNext()) { final Entry<String, Timer> timerEntry = timerIterator.next(); final String name = timerEntry.getKey(); final Timer timer = timerEntry.getValue(); final Snapshot snapshot = timer.getSnapshot(); // Add the meter info (mean rate and rate over time windows) addMeter(builder, name, EMPTY_STRING, timer.getCount(), timer.getMeanRate(), timer.getOneMinuteRate(), timer.getFiveMinuteRate(), timer.getFifteenMinuteRate()); // Count was already added via the meter addSnapshot(builder, name, EMPTY_STRING, snapshot); } } finally { dropwizardTimers = EMPTY_TIMER_MAP; } // Add in metadata about what the units the reported metrics are displayed using. builder.tag(RATE_UNIT_LABEL, getRateUnit()); builder.tag(DURATION_UNIT_LABEL, getDurationUnit()); }
From source file:org.apache.calcite.dropwizard.metrics.hadoop.HadoopMetrics2Reporter.java
License:Apache License
/** * Consumes the current metrics collected by dropwizard and adds them to the {@code builder}. * * @param builder A record builder//from w ww .j a v a2 s . c o m */ void snapshotAllMetrics(MetricsRecordBuilder builder) { // Pass through the gauges @SuppressWarnings("rawtypes") Iterator<Entry<String, Gauge>> gaugeIterator = dropwizardGauges.iterator(); while (gaugeIterator.hasNext()) { @SuppressWarnings("rawtypes") Entry<String, Gauge> gauge = gaugeIterator.next(); final MetricsInfo info = Interns.info(gauge.getKey(), EMPTY_STRING); final Object o = gauge.getValue().getValue(); // Figure out which gauge types metrics2 supports and call the right method if (o instanceof Integer) { builder.addGauge(info, (int) o); } else if (o instanceof Long) { builder.addGauge(info, (long) o); } else if (o instanceof Float) { builder.addGauge(info, (float) o); } else if (o instanceof Double) { builder.addGauge(info, (double) o); } else { LOG.info("Ignoring Gauge ({}) with unhandled type: {}", gauge.getKey(), o.getClass()); } gaugeIterator.remove(); } // Pass through the counters Iterator<Entry<String, Counter>> counterIterator = dropwizardCounters.iterator(); while (counterIterator.hasNext()) { Entry<String, Counter> counter = counterIterator.next(); MetricsInfo info = Interns.info(counter.getKey(), EMPTY_STRING); LOG.info("Adding counter {} {}", info, counter.getValue().getCount()); builder.addCounter(info, counter.getValue().getCount()); counterIterator.remove(); } // Pass through the histograms Iterator<Entry<String, Histogram>> histogramIterator = dropwizardHistograms.iterator(); while (histogramIterator.hasNext()) { final Entry<String, Histogram> entry = histogramIterator.next(); final String name = entry.getKey(); final Histogram histogram = entry.getValue(); addSnapshot(builder, name, EMPTY_STRING, histogram.getSnapshot(), histogram.getCount()); histogramIterator.remove(); } // Pass through the meter values Iterator<Entry<String, Meter>> meterIterator = dropwizardMeters.iterator(); while (meterIterator.hasNext()) { final Entry<String, Meter> meterEntry = meterIterator.next(); final String name = meterEntry.getKey(); final Meter meter = meterEntry.getValue(); addMeter(builder, name, EMPTY_STRING, meter.getCount(), meter.getMeanRate(), meter.getOneMinuteRate(), meter.getFiveMinuteRate(), meter.getFifteenMinuteRate()); meterIterator.remove(); } // Pass through the timers (meter + histogram) Iterator<Entry<String, Timer>> timerIterator = dropwizardTimers.iterator(); while (timerIterator.hasNext()) { final Entry<String, Timer> timerEntry = timerIterator.next(); final String name = timerEntry.getKey(); final Timer timer = timerEntry.getValue(); final Snapshot snapshot = timer.getSnapshot(); // Add the meter info (mean rate and rate over time windows) addMeter(builder, name, EMPTY_STRING, timer.getCount(), timer.getMeanRate(), timer.getOneMinuteRate(), timer.getFiveMinuteRate(), timer.getFifteenMinuteRate()); // Count was already added via the meter addSnapshot(builder, name, EMPTY_STRING, snapshot); timerIterator.remove(); } // Add in metadata about what the units the reported metrics are displayed using. builder.tag(RATE_UNIT_LABEL, getRateUnit()); builder.tag(DURATION_UNIT_LABEL, getDurationUnit()); }
From source file:org.apache.phoenix.trace.TraceMetricSource.java
License:Apache License
@Override public void getMetrics(MetricsCollector collector, boolean all) { // add a marker record so we know how many spans are used // this is also necessary to ensure that we register the metrics source as an MBean (avoiding a // runtime warning) MetricsRecordBuilder marker = collector.addRecord(TracingUtils.METRICS_MARKER_CONTEXT); marker.add(new MetricsTag(new MetricsInfoImpl("stat", "num spans"), Integer.toString(spans.size()))); // actually convert the known spans into metric records as well synchronized (this) { for (Metric span : spans) { MetricsRecordBuilder builder = collector .addRecord(new MetricsInfoImpl(TracingUtils.getTraceMetricName(span.id), span.desc)); builder.setContext(TracingUtils.METRICS_CONTEXT); for (Pair<MetricsInfo, Long> metric : span.counters) { builder.addCounter(metric.getFirst(), metric.getSecond()); }//from ww w .j a v a2s . c o m for (MetricsTag tag : span.tags) { builder.add(tag); } } // reset the spans so we don't keep a big chunk of memory around spans = new ArrayList<Metric>(); } }
From source file:org.apache.spark.network.yarn.YarnShuffleServiceMetrics.java
License:Apache License
/** * The metric types used in//from www. ja v a 2s. c o m * {@link org.apache.spark.network.shuffle.ExternalShuffleBlockHandler.ShuffleMetrics}. * Visible for testing. */ public static void collectMetric(MetricsRecordBuilder metricsRecordBuilder, String name, Metric metric) { if (metric instanceof Timer) { Timer t = (Timer) metric; metricsRecordBuilder .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of timer " + name), t.getCount()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of timer " + name), t.getFifteenMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of timer " + name), t.getFiveMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of timer " + name), t.getOneMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of timer " + name), t.getMeanRate()); } else if (metric instanceof Meter) { Meter m = (Meter) metric; metricsRecordBuilder .addCounter(new ShuffleServiceMetricsInfo(name + "_count", "Count of meter " + name), m.getCount()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate15", "15 minute rate of meter " + name), m.getFifteenMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate5", "5 minute rate of meter " + name), m.getFiveMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rate1", "1 minute rate of meter " + name), m.getOneMinuteRate()) .addGauge(new ShuffleServiceMetricsInfo(name + "_rateMean", "Mean rate of meter " + name), m.getMeanRate()); } else if (metric instanceof Gauge) { final Object gaugeValue = ((Gauge) metric).getValue(); if (gaugeValue instanceof Integer) { metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Integer) gaugeValue); } else if (gaugeValue instanceof Long) { metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Long) gaugeValue); } else if (gaugeValue instanceof Float) { metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Float) gaugeValue); } else if (gaugeValue instanceof Double) { metricsRecordBuilder.addGauge(getShuffleServiceMetricsInfo(name), (Double) gaugeValue); } else { throw new IllegalStateException( "Not supported class type of metric[" + name + "] for value " + gaugeValue); } } else if (metric instanceof Counter) { Counter c = (Counter) metric; long counterValue = c.getCount(); metricsRecordBuilder.addGauge( new ShuffleServiceMetricsInfo(name, "Number of " + "connections to shuffle service " + name), counterValue); } }