com.codahale.metrics.Histogram类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中com.codahale.metrics.Histogram类的一些代码示例,展示了Histogram类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Histogram类的具体详情如下:
包路径:com.codahale.metrics.Histogram
类名称:Histogram

Histogram介绍

[英]A metric which calculates the distribution of a value.
[中]计算值分布的一种度量。

代码示例

代码示例来源:origin: io.dropwizard.metrics/metrics-core

@Override
  public void run() {
    running.inc();
    final Timer.Context context = duration.time();
    try {
      command.run();
    } finally {
      final long elapsed = context.stop();
      running.dec();
      completed.mark();
      if (elapsed > periodInNanos) {
        scheduledOverrun.inc();
      }
      percentOfPeriod.update((100L * elapsed) / periodInNanos);
    }
  }
}

代码示例来源:origin: apache/hbase

private void printHistogram(Histogram histogram) {
  Snapshot snapshot = histogram.getSnapshot();
  output.printf(locale, "               min = %d%n", snapshot.getMin());
  output.printf(locale, "               max = %d%n", snapshot.getMax());
  output.printf(locale, "              mean = %2.2f%n", snapshot.getMean());
  output.printf(locale, "            stddev = %2.2f%n", snapshot.getStdDev());
  output.printf(locale, "            median = %2.2f%n", snapshot.getMedian());
  output.printf(locale, "              75%% <= %2.2f%n", snapshot.get75thPercentile());
  output.printf(locale, "              95%% <= %2.2f%n", snapshot.get95thPercentile());
  output.printf(locale, "              98%% <= %2.2f%n", snapshot.get98thPercentile());
  output.printf(locale, "              99%% <= %2.2f%n", snapshot.get99thPercentile());
  output.printf(locale, "            99.9%% <= %2.2f%n", snapshot.get999thPercentile());
  output.printf(locale, "             count = %d%n", histogram.getCount());
 }
}

代码示例来源:origin: micrometer-metrics/micrometer

@Setup(Level.Iteration)
public void setup() {
  registry = new MetricRegistry();
  histogram = registry.histogram("histogram");
  histogramSlidingTimeWindow =
      registry.register("slidingTimeWindowHistogram",
          new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS)));
  histogramUniform =
      registry.register("uniformHistogram",
          new Histogram(new UniformReservoir()));
}

代码示例来源:origin: stagemonitor/stagemonitor

public void writeValues(Histogram histogram, JsonGenerator jg) throws IOException {
    final Snapshot snapshot = histogram.getSnapshot();
    jg.writeNumberField("count", histogram.getCount());
    writeHistogramSnapshot(snapshot, jg);
  }
}

代码示例来源:origin: Graylog2/graylog2-server

public static Map<String, Object> buildHistogramMap(Histogram h) {
  Map<String, Object> metrics = Maps.newHashMap();
  if (h == null) {
    return metrics;
  }
  Map<String, Object> time = Maps.newHashMap();
  time.put("max", h.getSnapshot().getMax());
  time.put("min", h.getSnapshot().getMin());
  time.put("mean", (long) h.getSnapshot().getMean());
  time.put("95th_percentile", (long) h.getSnapshot().get95thPercentile());
  time.put("98th_percentile", (long) h.getSnapshot().get98thPercentile());
  time.put("99th_percentile", (long) h.getSnapshot().get99thPercentile());
  time.put("std_dev", (long) h.getSnapshot().getStdDev());
  metrics.put("time", time);
  metrics.put("count", h.getCount());
  return metrics;
}

代码示例来源:origin: apache/incubator-gobblin

totalRecordsCounter.inc();
recordProcessRateMeter.mark();
recordSizesHistogram.update((this.rand.nextLong() & Long.MAX_VALUE) % 5000l);
recordProcessTimeTimer.update(processTime, TimeUnit.MILLISECONDS);

代码示例来源:origin: apache/incubator-gobblin

com.codahale.metrics.Counter recordsProcessedCounter = new com.codahale.metrics.Counter();
recordsProcessedCounter.inc(10l);
Histogram recordSizeDistributionHistogram = new Histogram(new ExponentiallyDecayingReservoir());
recordSizeDistributionHistogram.update(1);
recordSizeDistributionHistogram.update(2);
recordSizeDistributionHistogram.update(3);
Meter recordProcessRateMeter = new Meter();
recordProcessRateMeter.mark(1l);
recordProcessRateMeter.mark(2l);
recordProcessRateMeter.mark(3l);
Timer totalDurationTimer = new Timer();
totalDurationTimer.update(1, TimeUnit.SECONDS);
totalDurationTimer.update(2, TimeUnit.SECONDS);
totalDurationTimer.update(3, TimeUnit.SECONDS);
Mockito.verify(this.queueSize).setValue(1000);
recordsProcessedCounter.inc(5l);
recordSizeDistributionHistogram.update(4);
recordProcessRateMeter.mark(4l);
totalDurationTimer.update(4, TimeUnit.SECONDS);

代码示例来源:origin: Graylog2/graylog2-server

@Override
protected void run() throws Exception {
  try {
    requestedReadCount = metricRegistry.register(name(this.getClass(), "requestedReadCount"), new HdrHistogram(processBuffer.getRingBufferSize() + 1, 3));
  } catch (IllegalArgumentException e) {
    log.warn("Metric already exists", e);
    requestedReadCount.update(remainingCapacity);
    final List<Journal.JournalReadEntry> encodedRawMessages = journal.read(remainingCapacity);
    if (encodedRawMessages.isEmpty()) {
        readBlocked.inc();
        journalFilled.acquire();
      } catch (InterruptedException ignored) {
      readMessages.mark(encodedRawMessages.size());
      log.debug("Processing {} messages from journal.", encodedRawMessages.size());
      for (final Journal.JournalReadEntry encodedRawMessage : encodedRawMessages) {

代码示例来源:origin: apache/hbase

/** @return a summary of {@code hist}. */
public static String getHistogramReport(final Histogram hist) {
 Snapshot sn = hist.getSnapshot();
 return "mean=" + DOUBLE_FORMAT.format(sn.getMean()) +
   ", min=" + DOUBLE_FORMAT.format(sn.getMin()) +
   ", max=" + DOUBLE_FORMAT.format(sn.getMax()) +
   ", stdDev=" + DOUBLE_FORMAT.format(sn.getStdDev()) +
   ", 50th=" + DOUBLE_FORMAT.format(sn.getMedian()) +
   ", 75th=" + DOUBLE_FORMAT.format(sn.get75thPercentile()) +
   ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) +
   ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile()) +
   ", 99.9th=" + DOUBLE_FORMAT.format(sn.get999thPercentile()) +
   ", 99.99th=" + DOUBLE_FORMAT.format(sn.getValue(0.9999)) +
   ", 99.999th=" + DOUBLE_FORMAT.format(sn.getValue(0.99999));
}

代码示例来源:origin: Graylog2/graylog2-server

private void flush(List<Map.Entry<IndexSet, Message>> messages) {
  // never try to flush an empty buffer
  if (messages.isEmpty()) {
    return;
  }
  activeFlushThreads.incrementAndGet();
  if (log.isDebugEnabled()) {
    log.debug("Starting flushing {} messages, flush threads active {}",
        messages.size(),
        activeFlushThreads.get());
  }
  try (Timer.Context ignored = processTime.time()) {
    lastFlushTime.set(System.nanoTime());
    writeMessageEntries(messages);
    batchSize.update(messages.size());
    bufferFlushes.mark();
  } catch (Exception e) {
    log.error("Unable to flush message buffer", e);
    bufferFlushFailures.mark();
  }
  activeFlushThreads.decrementAndGet();
  log.debug("Flushing {} messages completed", messages.size());
}

代码示例来源:origin: apache/kylin

Entry<String, Counter> counter = counterIterator.next();
MetricsInfo info = Interns.info(counter.getKey(), EMPTY_STRING);
builder.addCounter(info, counter.getValue().getCount());
final Histogram histogram = entry.getValue();
addSnapshot(builder, name, EMPTY_STRING, histogram.getSnapshot(), histogram.getCount());
final Meter meter = meterEntry.getValue();
addMeter(builder, name, EMPTY_STRING, meter.getCount(), meter.getMeanRate(), meter.getOneMinuteRate(),
    meter.getFiveMinuteRate(), meter.getFifteenMinuteRate());
final String name = timerEntry.getKey();
final Timer timer = timerEntry.getValue();
final Snapshot snapshot = timer.getSnapshot();
addMeter(builder, name, EMPTY_STRING, timer.getCount(), timer.getMeanRate(), timer.getOneMinuteRate(),
    timer.getFiveMinuteRate(), timer.getFifteenMinuteRate());

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private void update(long duration) {
    if (duration >= 0) {
      histogram.update(duration);
      meter.mark();
    }
  }
}

代码示例来源:origin: apache/incubator-gobblin

OutputStreamReporter.Factory.newBuilder().outputTo(this.stream).build(new Properties());
counter.inc();
meter.mark(2);
histogram.update(1);
histogram.update(1);
histogram.update(2);

代码示例来源:origin: biezhi/java-library-examples

public static void main(String[] args) throws InterruptedException {
    MetricRegistry  registry = new MetricRegistry();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).build();
    reporter.start(1, TimeUnit.SECONDS);
    Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
    registry.register(MetricRegistry.name(HistogramExample.class, "request", "histogram"), histogram);

    while (true) {
      Thread.sleep(1000);
      histogram.update(random.nextInt(100000));
    }
  }
}

代码示例来源:origin: apache/hbase

/** @return an abbreviated summary of {@code hist}. */
public static String getShortHistogramReport(final Histogram hist) {
 Snapshot sn = hist.getSnapshot();
 return "mean=" + DOUBLE_FORMAT.format(sn.getMean()) +
   ", min=" + DOUBLE_FORMAT.format(sn.getMin()) +
   ", max=" + DOUBLE_FORMAT.format(sn.getMax()) +
   ", stdDev=" + DOUBLE_FORMAT.format(sn.getStdDev()) +
   ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) +
   ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile());
}

代码示例来源:origin: HotelsDotCom/styx

private void updateChannelPerThreadCounters(int amount) {
  Thread thread = Thread.currentThread();
  Counter channelCount = this.metricRegistry.counter(name(counterPrefix(thread), "registered-channel-count"));
  channelCount.inc(amount);
  Histogram histogram = metricRegistry.histogram(name(counterPrefix(thread), "channels"));
  histogram.update(channelCount.getCount());
}

代码示例来源:origin: thinkaurelius/titan

private void recordSliceMetrics(StoreTransaction txh, List<Entry> row) {
  if (!txh.getConfiguration().hasGroupName())
    return;
  String p = txh.getConfiguration().getGroupName();
  final MetricManager mgr = MetricManager.INSTANCE;
  mgr.getCounter(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_COUNT).inc(row.size());
  mgr.getHistogram(p, metricsStoreName, M_GET_SLICE, M_ENTRIES_HISTO).update(row.size());
}

代码示例来源:origin: weibocom/motan

.histogram(HISTOGRAM_NAME).getSnapshot();
    "[motan-accessStatistic] app: {} module: {} item: {} total_count: {} slow_count: {} p75: {} p95: {} p98: {} p99: {} p999: {} biz_excp: {} other_excp: {} avg_time: {}ms biz_time: {}ms avg_tps: {} max_tps: {} min_tps: {} ",
    application, module, keys[0], result.totalCount, result.slowCount,
    mbFormat.format(snapshot.get75thPercentile()), mbFormat.format(snapshot.get95thPercentile()),
    mbFormat.format(snapshot.get98thPercentile()), mbFormat.format(snapshot.get99thPercentile()),
    mbFormat.format(snapshot.get999thPercentile()), result.bizExceptionCount, result.otherExceptionCount,
    mbFormat.format(result.costTime / result.totalCount), mbFormat.format(result.bizTime / result.totalCount),
Snapshot snapshot =
    InternalMetricsFactory.getRegistryInstance(entry.getKey())
        .histogram(HISTOGRAM_NAME).getSnapshot();
if (totalResult.totalCount > 0) {
  LoggerUtil.accessStatsLog(

代码示例来源:origin: Graylog2/graylog2-server

private void recordEsMetrics(JestResult jestResult, @Nullable TimeRange range) {
  esTotalSearchesCounter.inc();
  final long tookMs = tookMsFromSearchResult(jestResult);
  esRequestTimer.update(tookMs, TimeUnit.MILLISECONDS);
  if (range != null) {
    esTimeRangeHistogram.update(TimeRanges.toSeconds(range));
  }
}

代码示例来源:origin: apache/zookeeper

public Map<String, Object> values() {
    Map<String, Object> m = new LinkedHashMap<>();
    m.putAll(counter.values());
    m.put("p50_" + name, Math.round(this.histogram.getSnapshot().getMedian()));
    m.put("p95_" + name, Math.round(this.histogram.getSnapshot().get95thPercentile()));
    m.put("p99_" + name, Math.round(this.histogram.getSnapshot().get99thPercentile()));
    m.put("p999_" + name, Math.round(this.histogram.getSnapshot().get999thPercentile()));
    return m;
  }
}

相关文章