Java Code Examples for org.apache.hadoop.metrics2.MetricsRecordBuilder#addGauge()

The following examples show how to use org.apache.hadoop.metrics2.MetricsRecordBuilder#addGauge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricsStochasticBalancerSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

  if (stochasticCosts != null) {
    synchronized (stochasticCosts) {
      for (Map.Entry<String, Map<String, Double>> tableEntry : stochasticCosts.entrySet()) {
        for (Map.Entry<String, Double> costEntry : tableEntry.getValue().entrySet()) {
          String attrName = tableEntry.getKey() + TABLE_FUNCTION_SEP + costEntry.getKey();
          Double cost = costEntry.getValue();
          String functionDesc = costFunctionDescs.get(costEntry.getKey());

          if (functionDesc == null) {
            functionDesc = costEntry.getKey();
          }

          metricsRecordBuilder.addGauge(Interns.info(attrName, functionDesc), cost);
        }
      }
    }
  }
  metricsRegistry.snapshot(metricsRecordBuilder, all);
}
 
Example 2
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void addGauge(String name, Gauge<?> gauge, MetricsRecordBuilder builder) {
  final MetricsInfo info = Interns.info(name, EMPTY_STRING);
  final Object o = gauge.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.warn("Ignoring Gauge (" + name + ") with unhandled type: " + o.getClass());
  }
}
 
Example 3
Source File: StartupProgressMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 4
Source File: MutableHistogram.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected static void updateSnapshotMetrics(String name, String desc, Histogram histogram,
    Snapshot snapshot, MetricsRecordBuilder metricsRecordBuilder) {
  metricsRecordBuilder.addCounter(Interns.info(name + NUM_OPS_METRIC_NAME, desc),
      histogram.getCount());
  metricsRecordBuilder.addGauge(Interns.info(name + MIN_METRIC_NAME, desc), snapshot.getMin());
  metricsRecordBuilder.addGauge(Interns.info(name + MAX_METRIC_NAME, desc), snapshot.getMax());
  metricsRecordBuilder.addGauge(Interns.info(name + MEAN_METRIC_NAME, desc), snapshot.getMean());

  metricsRecordBuilder.addGauge(Interns.info(name + TWENTY_FIFTH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get25thPercentile());
  metricsRecordBuilder.addGauge(Interns.info(name + MEDIAN_METRIC_NAME, desc),
      snapshot.getMedian());
  metricsRecordBuilder.addGauge(Interns.info(name + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get75thPercentile());
  metricsRecordBuilder.addGauge(Interns.info(name + NINETIETH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get90thPercentile());
  metricsRecordBuilder.addGauge(Interns.info(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get95thPercentile());
  metricsRecordBuilder.addGauge(Interns.info(name + NINETY_EIGHTH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get98thPercentile());
  metricsRecordBuilder.addGauge(Interns.info(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get99thPercentile());
  metricsRecordBuilder.addGauge(
      Interns.info(name + NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC_NAME, desc),
      snapshot.get999thPercentile());
}
 
Example 5
Source File: MutableQuantiles.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addGauge(numInfo, previousCount);
    for (int i = 0; i < quantiles.length; i++) {
      long newValue = 0;
      // If snapshot is null, we failed to update since the window was empty
      if (previousSnapshot != null) {
        newValue = previousSnapshot.get(quantiles[i]);
      }
      builder.addGauge(quantileInfos[i], newValue);
    }
    if (changed()) {
      clearChanged();
    }
  }
}
 
Example 6
Source File: MethodMetric.java    From hadoop with Apache License 2.0 6 votes vote down vote up
MutableMetric newGauge(final Class<?> t) {
  if (isInt(t) || isLong(t) || isFloat(t) || isDouble(t)) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[]) null);
          if (isInt(t)) rb.addGauge(info, ((Integer) ret).intValue());
          else if (isLong(t)) rb.addGauge(info, ((Long) ret).longValue());
          else if (isFloat(t)) rb.addGauge(info, ((Float) ret).floatValue());
          else rb.addGauge(info, ((Double) ret).doubleValue());
        }
        catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported gauge type: "+ t.getName());
}
 
Example 7
Source File: MetricsMasterProcSourceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

  // masterWrapper can be null because this function is called inside of init.
  if (masterWrapper != null) {
    metricsRecordBuilder
        .addGauge(Interns.info(NUM_MASTER_WALS_NAME, NUM_MASTER_WALS_DESC),
            masterWrapper.getNumWALFiles());
  }

  metricsRegistry.snapshot(metricsRecordBuilder, all);
  if(metricsAdapter != null) {
    metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
  }
}
 
Example 8
Source File: StartupProgressMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 9
Source File: GlobalMetricRegistriesAdapter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void addGauge(String name, Gauge<?> gauge, MetricsRecordBuilder builder) {
    MetricsInfo info = Interns.info(name, "");
    Object o = gauge.getValue();
    if (o instanceof Integer) {
        builder.addGauge(info, (Integer)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 {
        LOGGER.warn("Ignoring Gauge (" + name + ") with unhandled type: " + o.getClass());
    }

}
 
Example 10
Source File: MutableGaugeInt.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addGauge(info(), value());
    clearChanged();
  }
}
 
Example 11
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting
 * the durations to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for this record.
 * @param snapshot The distribution of measured values.
 */
private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot) {
    builder.addGauge(Interns.info(name + "_mean", desc), convertDuration(snapshot.getMean()));
    builder.addGauge(Interns.info(name + "_min", desc), convertDuration(snapshot.getMin()));
    builder.addGauge(Interns.info(name + "_max", desc), convertDuration(snapshot.getMax()));
    builder.addGauge(Interns.info(name + "_median", desc), convertDuration(snapshot.getMedian()));
    builder.addGauge(Interns.info(name + "_stddev", desc), convertDuration(snapshot.getStdDev()));

    builder.addGauge(Interns.info(name + "_75thpercentile", desc), convertDuration(snapshot.get75thPercentile()));
    builder.addGauge(Interns.info(name + "_95thpercentile", desc), convertDuration(snapshot.get95thPercentile()));
    builder.addGauge(Interns.info(name + "_98thpercentile", desc), convertDuration(snapshot.get98thPercentile()));
    builder.addGauge(Interns.info(name + "_99thpercentile", desc), convertDuration(snapshot.get99thPercentile()));
    builder.addGauge(Interns.info(name + "_999thpercentile", desc), convertDuration(snapshot.get999thPercentile()));
}
 
Example 12
Source File: MetricsTableSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void addGauge(MetricsRecordBuilder mrb, Map<String, Long> metricMap, String metricName,
    String metricDesc) {
  if (metricMap != null) {
    for (Entry<String, Long> entry : metricMap.entrySet()) {
      // append 'store' and its name to the metric
      mrb.addGauge(Interns.info(this.tableNamePrefixPart1 + _COLUMNFAMILY
          + entry.getKey().split(MetricsTableWrapperAggregate.UNDERSCORE)[1]
          + this.tableNamePrefixPart2 + metricName,
        metricDesc), entry.getValue());
    }
  }
}
 
Example 13
Source File: MutableGaugeInt.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addGauge(info(), value());
    clearChanged();
  }
}
 
Example 14
Source File: MutableGaugeLong.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addGauge(info(), value());
    clearChanged();
  }
}
 
Example 15
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 3 votes vote down vote up
/**
 * Add Dropwizard-Metrics rate information to a Hadoop-Metrics2 record builder, converting the
 * rates to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for the record.
 * @param count The number of measured events.
 * @param meanRate The average measured rate.
 * @param oneMinuteRate The measured rate over the past minute.
 * @param fiveMinuteRate The measured rate over the past five minutes
 * @param fifteenMinuteRate The measured rate over the past fifteen minutes.
 */
private void addMeter(MetricsRecordBuilder builder, String name, String desc, long count, double meanRate,
        double oneMinuteRate, double fiveMinuteRate, double fifteenMinuteRate) {
    builder.addGauge(Interns.info(name + "_count", EMPTY_STRING), count);
    builder.addGauge(Interns.info(name + "_mean_rate", EMPTY_STRING), convertRate(meanRate));
    builder.addGauge(Interns.info(name + "_1min_rate", EMPTY_STRING), convertRate(oneMinuteRate));
    builder.addGauge(Interns.info(name + "_5min_rate", EMPTY_STRING), convertRate(fiveMinuteRate));
    builder.addGauge(Interns.info(name + "_15min_rate", EMPTY_STRING), convertRate(fifteenMinuteRate));
}
 
Example 16
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 3 votes vote down vote up
/**
 * Add Dropwizard-Metrics rate information to a Hadoop-Metrics2 record builder, converting the
 * rates to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for the record.
 * @param count The number of measured events.
 * @param meanRate The average measured rate.
 * @param oneMinuteRate The measured rate over the past minute.
 * @param fiveMinuteRate The measured rate over the past five minutes
 * @param fifteenMinuteRate The measured rate over the past fifteen minutes.
 */
private void addMeter(MetricsRecordBuilder builder, String name, String desc, long count, double meanRate,
        double oneMinuteRate, double fiveMinuteRate, double fifteenMinuteRate) {
    builder.addGauge(Interns.info(name + "_count", EMPTY_STRING), count);
    builder.addGauge(Interns.info(name + "_mean_rate", EMPTY_STRING), convertRate(meanRate));
    builder.addGauge(Interns.info(name + "_1min_rate", EMPTY_STRING), convertRate(oneMinuteRate));
    builder.addGauge(Interns.info(name + "_5min_rate", EMPTY_STRING), convertRate(fiveMinuteRate));
    builder.addGauge(Interns.info(name + "_15min_rate", EMPTY_STRING), convertRate(fifteenMinuteRate));
}
 
Example 17
Source File: StartupProgressMetrics.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a gauge with a name built by using the specified phase's name as prefix
 * and then appending the specified suffix.
 * 
 * @param builder MetricsRecordBuilder to receive counter
 * @param phase Phase to add
 * @param nameSuffix String suffix of metric name
 * @param descSuffix String suffix of metric description
 * @param value float gauge value
 */
private static void addGauge(MetricsRecordBuilder builder, Phase phase,
    String nameSuffix, String descSuffix, float value) {
  MetricsInfo metricsInfo = info(phase.getName() + nameSuffix,
    phase.getDescription() + descSuffix);
  builder.addGauge(metricsInfo, value);
}
 
Example 18
Source File: StartupProgressMetrics.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a gauge with a name built by using the specified phase's name as prefix
 * and then appending the specified suffix.
 * 
 * @param builder MetricsRecordBuilder to receive counter
 * @param phase Phase to add
 * @param nameSuffix String suffix of metric name
 * @param descSuffix String suffix of metric description
 * @param value float gauge value
 */
private static void addGauge(MetricsRecordBuilder builder, Phase phase,
    String nameSuffix, String descSuffix, float value) {
  MetricsInfo metricsInfo = info(phase.getName() + nameSuffix,
    phase.getDescription() + descSuffix);
  builder.addGauge(metricsInfo, value);
}
 
Example 19
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 2 votes vote down vote up
/**
 * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting
 * the durations to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for this record.
 * @param snapshot The distribution of measured values.
 * @param count The number of values which were measured.
 */
private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot, long count) {
    builder.addGauge(Interns.info(name + "_count", desc), count);
    addSnapshot(builder, name, desc, snapshot);
}
 
Example 20
Source File: HadoopMetrics2Reporter.java    From kylin with Apache License 2.0 2 votes vote down vote up
/**
 * Add Dropwizard-Metrics value-distribution data to a Hadoop-Metrics2 record building, converting
 * the durations to the appropriate unit.
 *
 * @param builder A Hadoop-Metrics2 record builder.
 * @param name A base name for this record.
 * @param desc A description for this record.
 * @param snapshot The distribution of measured values.
 * @param count The number of values which were measured.
 */
private void addSnapshot(MetricsRecordBuilder builder, String name, String desc, Snapshot snapshot, long count) {
    builder.addGauge(Interns.info(name + "_count", desc), count);
    addSnapshot(builder, name, desc, snapshot);
}