org.rocksdb.HistogramType Java Examples

The following examples show how to use org.rocksdb.HistogramType. 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: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {

  List<MBeanAttributeInfo> attributes = new ArrayList<>();
  for (TickerType tickerType : TickerType.values()) {
    attributes.add(new MBeanAttributeInfo(tickerType.name(), "long",
        "RocksDBStat: " + tickerType.name(), true, false, false));
  }
  for (HistogramType histogramType : HistogramType.values()) {
    for (String histogramAttribute : histogramAttributes) {
      attributes.add(new MBeanAttributeInfo(
          histogramType.name() + "_" + histogramAttribute.toUpperCase(),
          "long", "RocksDBStat: " + histogramType.name(), true, false,
          false));
    }
  }

  return new MBeanInfo("", "RocksDBStat",
      attributes.toArray(new MBeanAttributeInfo[0]), null, null, null);

}
 
Example #2
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Collect all histogram metrics from RocksDB statistics.
 * @param rb Metrics Record Builder.
 */
private void getHistogramData(MetricsRecordBuilder rb) {
  for (HistogramType histogramType : HistogramType.values()) {
    HistogramData histogram =
        statistics.getHistogramData(
            HistogramType.valueOf(histogramType.name()));
    for (String histogramAttribute : histogramAttributes) {
      try {
        Method method =
            HistogramData.class.getMethod("get" + histogramAttribute);
        double metricValue =  (double) method.invoke(histogram);
        rb.addGauge(Interns.info(histogramType.name() + "_" +
                histogramAttribute.toUpperCase(), "RocksDBStat"),
            metricValue);
      } catch (Exception e) {
        LOG.error("Error reading histogram data", e);
      }
    }
  }
}
 
Example #3
Source File: RocksDBStats.java    From besu with Apache License 2.0 6 votes vote down vote up
public static void registerRocksDBMetrics(
    final Statistics stats,
    final PrometheusMetricsSystem metricsSystem,
    final MetricCategory category) {
  for (final TickerType ticker : TICKERS) {
    final String promCounterName = ticker.name().toLowerCase();
    metricsSystem.createLongGauge(
        category,
        promCounterName,
        "RocksDB reported statistics for " + ticker.name(),
        () -> stats.getTickerCount(ticker));
  }

  for (final HistogramType histogram : HISTOGRAMS) {
    metricsSystem.addCollector(category, histogramToCollector(stats, histogram));
  }
}
 
Example #4
Source File: RocksDBStats.java    From besu with Apache License 2.0 6 votes vote down vote up
private static Collector histogramToCollector(
    final Statistics stats, final HistogramType histogram) {
  return new Collector() {
    final String metricName =
        KVSTORE_ROCKSDB_STATS.getName() + "_" + histogram.name().toLowerCase();

    @Override
    public List<MetricFamilySamples> collect() {
      final HistogramData data = stats.getHistogramData(histogram);
      return Collections.singletonList(
          new MetricFamilySamples(
              metricName,
              Type.SUMMARY,
              "RocksDB histogram for " + metricName,
              Arrays.asList(
                  new MetricFamilySamples.Sample(metricName, LABELS, LABEL_50, data.getMedian()),
                  new MetricFamilySamples.Sample(
                      metricName, LABELS, LABEL_95, data.getPercentile95()),
                  new MetricFamilySamples.Sample(
                      metricName, LABELS, LABEL_99, data.getPercentile99()))));
    }
  };
}
 
Example #5
Source File: RocksDbStats.java    From teku with Apache License 2.0 6 votes vote down vote up
public void registerMetrics() {
  for (final TickerType ticker : TICKERS) {
    final String promCounterName = ticker.name().toLowerCase();
    metricsSystem.createLongGauge(
        category,
        promCounterName,
        "RocksDB reported statistics for " + ticker.name(),
        () -> ifOpen(() -> stats.getTickerCount(ticker), 0L));
  }

  if (metricsSystem instanceof PrometheusMetricsSystem) {
    for (final HistogramType histogram : HISTOGRAMS) {
      ((PrometheusMetricsSystem) metricsSystem)
          .addCollector(category, histogramToCollector(category, stats, histogram));
    }
  }
}
 
Example #6
Source File: RocksDBStoreMBean.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  for (String histogramAttribute : histogramAttributes) {
    if (attribute.endsWith("_" + histogramAttribute.toUpperCase())) {
      String keyName = attribute
          .substring(0, attribute.length() - histogramAttribute.length() - 1);
      try {
        HistogramData histogram =
            statistics.getHistogramData(HistogramType.valueOf(keyName));
        try {
          Method method =
              HistogramData.class.getMethod("get" + histogramAttribute);
          return method.invoke(histogram);
        } catch (Exception e) {
          throw new ReflectionException(e,
              "Can't read attribute " + attribute);
        }
      } catch (IllegalArgumentException exception) {
        throw new AttributeNotFoundException(
            "No such attribute in RocksDB stats: " + attribute);
      }
    }
  }
  try {
    return statistics.getTickerCount(TickerType.valueOf(attribute));
  } catch (IllegalArgumentException ex) {
    throw new AttributeNotFoundException(
        "No such attribute in RocksDB stats: " + attribute);
  }
}
 
Example #7
Source File: RocksStatistics.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the histogram data for a particular histogram.
 */
public static HistogramData getHistogramData(final RocksRawKVStore rocksRawKVStore,
                                             final HistogramType histogramType) {
    final Statistics statistics = statistics(rocksRawKVStore);
    if (statistics == null) {
        return null;
    }
    return statistics.getHistogramData(histogramType);
}
 
Example #8
Source File: RocksStatistics.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a string representation of a particular histogram.
 */
public String getHistogramString(final RocksRawKVStore rocksRawKVStore, final HistogramType histogramType) {
    final Statistics statistics = statistics(rocksRawKVStore);
    if (statistics == null) {
        return "";
    }
    return statistics.getHistogramString(histogramType);
}
 
Example #9
Source File: RocksDbStats.java    From teku with Apache License 2.0 5 votes vote down vote up
private Collector histogramToCollector(
    final MetricCategory metricCategory, final Statistics stats, final HistogramType histogram) {
  return new Collector() {
    final String metricName =
        metricCategory.getApplicationPrefix().orElse("")
            + metricCategory.getName()
            + "_"
            + histogram.name().toLowerCase();

    @Override
    public List<MetricFamilySamples> collect() {
      return ifOpen(
          () -> {
            final HistogramData data = stats.getHistogramData(histogram);
            return Collections.singletonList(
                new MetricFamilySamples(
                    metricName,
                    Type.SUMMARY,
                    "RocksDB histogram for " + metricName,
                    Arrays.asList(
                        new MetricFamilySamples.Sample(
                            metricName, LABELS, LABEL_50, data.getMedian()),
                        new MetricFamilySamples.Sample(
                            metricName, LABELS, LABEL_95, data.getPercentile95()),
                        new MetricFamilySamples.Sample(
                            metricName, LABELS, LABEL_99, data.getPercentile99()))));
          },
          Collections.emptyList());
    }
  };
}