Java Code Examples for io.micrometer.core.instrument.Timer#takeSnapshot()

The following examples show how to use io.micrometer.core.instrument.Timer#takeSnapshot() . 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: AbstractPerfPrinter.java    From pepper-metrics with Apache License 2.0 4 votes vote down vote up
private List<PrinterDomain> collector(Stats stats, ConcurrentMap<String, ConcurrentMap<List<String>, Double>> currentErrCollector,
                                      ConcurrentMap<String, ConcurrentMap<List<String>, Long>> currentSummaryCollector) {
    ConcurrentMap<List<String>, Counter> errCollector = stats.getErrCollector();
    ConcurrentMap<List<String>, AtomicLong> gaugeCollector = stats.getGaugeCollector();
    ConcurrentMap<List<String>, Timer> summaryCollector = stats.getSummaryCollector();

    // 记录上一次的error数
    currentErrCollector.put(buildCollectorKey(stats), parseErrCollector(errCollector));
    currentSummaryCollector.put(buildCollectorKey(stats), parseSummaryCollector(summaryCollector));

    List<PrinterDomain> retList = new ArrayList<>();

    for (Map.Entry<List<String>, Timer> entry : summaryCollector.entrySet()) {
        List<String> tag = entry.getKey();
        Timer summary= entry.getValue();

        Counter counter = errCollector.get(tag);
        AtomicLong concurrent = gaugeCollector.get(tag);

        PrinterDomain domain = new PrinterDomain();

        String name = setMetricsName(stats, tag);
        HistogramSnapshot snapshot = summary.takeSnapshot();

        domain.setTag(name);

        domain.setConcurrent(concurrent == null ? "0" : concurrent.toString());
        domain.setErr(counter == null ? "0" : String.valueOf(counter.count() - getLastTimeErrCount(stats, entry.getKey())));
        domain.setSum(String.valueOf(snapshot.count() - getLastTimeSummaryCount(stats, entry.getKey())));
        ValueAtPercentile[] vps = snapshot.percentileValues();
        for (ValueAtPercentile vp : vps) {
            if (vp.percentile() == 0.9D) {
                domain.setP90(String.valueOf(vp.value(TimeUnit.MILLISECONDS)));
            } else if (vp.percentile() == 0.99D) {
                domain.setP99(String.valueOf(vp.value(TimeUnit.MILLISECONDS)));
            } else if (vp.percentile() == 0.999D) {
                domain.setP999(String.valueOf(vp.value(TimeUnit.MILLISECONDS)));
            } else if (vp.percentile() == 0.99999D) {
                domain.setMax(String.valueOf(vp.value(TimeUnit.MILLISECONDS)));
            }
        }

        // 计算qps
        domain.setQps(String.format("%.1f", Float.parseFloat(domain.getSum()) / 60));

        retList.add(domain);
    }

    return retList;
}
 
Example 2
Source File: DefaultDestinationPublishingMeterRegistry.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
private Metric<Number> toTimerMetric(Timer timer) {
	return new Metric<Number>(timer.getId(), timer.takeSnapshot());
}