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

The following examples show how to use org.apache.hadoop.metrics2.MetricsRecordBuilder#addCounter() . 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: 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 2
Source File: JvmMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThreadholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
Example 3
Source File: MethodMetric.java    From hadoop with Apache License 2.0 6 votes vote down vote up
MutableMetric newCounter(final Class<?> type) {
  if (isInt(type) || isLong(type)) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[])null);
          if (isInt(type)) rb.addCounter(info, ((Integer) ret).intValue());
          else rb.addCounter(info, ((Long) ret).longValue());
        }
        catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported counter type: "+ type.getName());
}
 
Example 4
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 5
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 6
Source File: JvmMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void getGcUsage(MetricsRecordBuilder rb) {
  long count = 0;
  long timeMillis = 0;
  for (GarbageCollectorMXBean gcBean : gcBeans) {
    long c = gcBean.getCollectionCount();
    long t = gcBean.getCollectionTime();
    MetricsInfo[] gcInfo = getGcInfo(gcBean.getName());
    rb.addCounter(gcInfo[0], c).addCounter(gcInfo[1], t);
    count += c;
    timeMillis += t;
  }
  rb.addCounter(GcCount, count)
    .addCounter(GcTimeMillis, timeMillis);
  
  if (pauseMonitor != null) {
    rb.addCounter(GcNumWarnThresholdExceeded,
        pauseMonitor.getNumGcWarnThreadholdExceeded());
    rb.addCounter(GcNumInfoThresholdExceeded,
        pauseMonitor.getNumGcInfoThresholdExceeded());
    rb.addCounter(GcTotalExtraSleepTime,
        pauseMonitor.getTotalGcExtraSleepTime());
  }
}
 
Example 7
Source File: MethodMetric.java    From big-c with Apache License 2.0 6 votes vote down vote up
MutableMetric newCounter(final Class<?> type) {
  if (isInt(type) || isLong(type)) {
    return new MutableMetric() {
      @Override public void snapshot(MetricsRecordBuilder rb, boolean all) {
        try {
          Object ret = method.invoke(obj, (Object[])null);
          if (isInt(type)) rb.addCounter(info, ((Integer) ret).intValue());
          else rb.addCounter(info, ((Long) ret).longValue());
        }
        catch (Exception ex) {
          LOG.error("Error invoking method "+ method.getName(), ex);
        }
      }
    };
  }
  throw new MetricsException("Unsupported counter type: "+ type.getName());
}
 
Example 8
Source File: MutableCounterLong.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.addCounter(info(), value());
    clearChanged();
  }
}
 
Example 9
Source File: MetricsIOSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);

  // wrapper can be null because this function is called inside of init.
  if (wrapper != null) {
    mrb.addCounter(Interns.info(CHECKSUM_FAILURES_KEY, CHECKSUM_FAILURES_DESC),
      wrapper.getChecksumFailures());
  }

  metricsRegistry.snapshot(mrb, all);
}
 
Example 10
Source File: MetricsRegionSourceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void addCounter(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.addCounter(Interns.info(
        this.regionNamePrefix1 + _STORE + entry.getKey() + this.regionNamePrefix2 + metricName,
        metricDesc), entry.getValue());
    }
  }
}
 
Example 11
Source File: MutableFastCounter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void snapshot(MetricsRecordBuilder builder, boolean all) {
  if (all || changed()) {
    builder.addCounter(info(), value());
    clearChanged();
  }
}
 
Example 12
Source File: MutableCounterInt.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.addCounter(info(), value());
    clearChanged();
  }
}
 
Example 13
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Collect all Counter metrics from RocksDB statistics.
 * @param rb Metrics Record Builder.
 */
private void getTickerTypeData(MetricsRecordBuilder rb) {
  for (TickerType tickerType : TickerType.values()) {
    rb.addCounter(Interns.info(tickerType.name(), "RocksDBStat"),
        statistics.getTickerCount(tickerType));
  }
}
 
Example 14
Source File: MutableCounterInt.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.addCounter(info(), value());
    clearChanged();
  }
}
 
Example 15
Source File: MutableCounterLong.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.addCounter(info(), value());
    clearChanged();
  }
}
 
Example 16
Source File: HBaseMetrics2HadoopMetricsAdapter.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void addCounter(String name, Counter counter, MetricsRecordBuilder builder) {
  MetricsInfo info = Interns.info(name, EMPTY_STRING);
  builder.addCounter(info, counter.getCount());
}
 
Example 17
Source File: MetricsTableSourceImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
  // If there is a close that started be double extra sure
  // that we're not getting any locks and not putting data
  // into the metrics that should be removed. So early out
  // before even getting the lock.
  if (closed.get()) {
    return;
  }

  // Grab the read
  // This ensures that removes of the metrics
  // can't happen while we are putting them back in.
  synchronized (this) {
    // It's possible that a close happened between checking
    // the closed variable and getting the lock.
    if (closed.get()) {
      return;
    }

    if (this.tableWrapperAgg != null) {
      mrb.addCounter(Interns.info(tableNamePrefix + MetricsRegionServerSource.CP_REQUEST_COUNT,
          MetricsRegionServerSource.CP_REQUEST_COUNT_DESC),
        tableWrapperAgg.getCpRequestsCount(tableName.getNameAsString()));
      mrb.addCounter(Interns.info(tableNamePrefix + MetricsRegionServerSource.READ_REQUEST_COUNT,
          MetricsRegionServerSource.READ_REQUEST_COUNT_DESC),
          tableWrapperAgg.getReadRequestCount(tableName.getNameAsString()));
      mrb.addCounter(
          Interns.info(tableNamePrefix + MetricsRegionServerSource.FILTERED_READ_REQUEST_COUNT,
              MetricsRegionServerSource.FILTERED_READ_REQUEST_COUNT_DESC),
          tableWrapperAgg.getFilteredReadRequestCount(tableName.getNameAsString()));
      mrb.addCounter(Interns.info(tableNamePrefix + MetricsRegionServerSource.WRITE_REQUEST_COUNT,
          MetricsRegionServerSource.WRITE_REQUEST_COUNT_DESC),
          tableWrapperAgg.getWriteRequestCount(tableName.getNameAsString()));
      mrb.addCounter(Interns.info(tableNamePrefix + MetricsRegionServerSource.TOTAL_REQUEST_COUNT,
          MetricsRegionServerSource.TOTAL_REQUEST_COUNT_DESC),
          tableWrapperAgg.getTotalRequestsCount(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.MEMSTORE_SIZE,
          MetricsRegionServerSource.MEMSTORE_SIZE_DESC),
          tableWrapperAgg.getMemStoreSize(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.STOREFILE_COUNT,
          MetricsRegionServerSource.STOREFILE_COUNT_DESC),
          tableWrapperAgg.getNumStoreFiles(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.STOREFILE_SIZE,
          MetricsRegionServerSource.STOREFILE_SIZE_DESC),
          tableWrapperAgg.getStoreFileSize(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsTableSource.TABLE_SIZE,
        MetricsTableSource.TABLE_SIZE_DESC),
        tableWrapperAgg.getTableSize(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.AVERAGE_REGION_SIZE,
          MetricsRegionServerSource.AVERAGE_REGION_SIZE_DESC),
          tableWrapperAgg.getAvgRegionSize(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.REGION_COUNT,
          MetricsRegionServerSource.REGION_COUNT_DESC),
          tableWrapperAgg.getNumRegions(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.STORE_COUNT,
          MetricsRegionServerSource.STORE_COUNT_DESC),
          tableWrapperAgg.getNumStores(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.MAX_STORE_FILE_AGE,
          MetricsRegionServerSource.MAX_STORE_FILE_AGE_DESC),
          tableWrapperAgg.getMaxStoreFileAge(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.MIN_STORE_FILE_AGE,
          MetricsRegionServerSource.MIN_STORE_FILE_AGE_DESC),
          tableWrapperAgg.getMinStoreFileAge(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.AVG_STORE_FILE_AGE,
          MetricsRegionServerSource.AVG_STORE_FILE_AGE_DESC),
          tableWrapperAgg.getAvgStoreFileAge(tableName.getNameAsString()));
      mrb.addGauge(Interns.info(tableNamePrefix + MetricsRegionServerSource.NUM_REFERENCE_FILES,
          MetricsRegionServerSource.NUM_REFERENCE_FILES_DESC),
          tableWrapperAgg.getNumReferenceFiles(tableName.getNameAsString()));
      addGauge(mrb, tableWrapperAgg.getMemstoreOnlyRowReadsCount(tableName.getNameAsString()),
        MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE,
        MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE_DESC);
      addGauge(mrb, tableWrapperAgg.getMixedRowReadsCount(tableName.getNameAsString()),
        MetricsRegionSource.MIXED_ROW_READS,
        MetricsRegionSource.MIXED_ROW_READS_ON_STORE_DESC);
    }
  }
}
 
Example 18
Source File: GlobalMetricRegistriesAdapter.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void addCounter(String name, Counter counter, MetricsRecordBuilder builder) {
    MetricsInfo info = Interns.info(name, "");
    builder.addCounter(info, counter.getCount());
}
 
Example 19
Source File: StartupProgressMetrics.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a counter 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 long counter value
 */
private static void addCounter(MetricsRecordBuilder builder, Phase phase,
    String nameSuffix, String descSuffix, long value) {
  MetricsInfo metricsInfo = info(phase.getName() + nameSuffix,
    phase.getDescription() + descSuffix);
  builder.addCounter(metricsInfo, value);
}
 
Example 20
Source File: StartupProgressMetrics.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a counter 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 long counter value
 */
private static void addCounter(MetricsRecordBuilder builder, Phase phase,
    String nameSuffix, String descSuffix, long value) {
  MetricsInfo metricsInfo = info(phase.getName() + nameSuffix,
    phase.getDescription() + descSuffix);
  builder.addCounter(metricsInfo, value);
}