gpt4 book ai didi

java - Codahale 指标计数器每天重置并计数

转载 作者:行者123 更新时间:2023-12-01 09:33:30 25 4
gpt4 key购买 nike

使用 Codahale 指标可以计算过去 24 小时(今天)的数据。

生成如下报告:

请求计数:

lastSec   lastMin    lastHour    today
=======================================
1 5 22 45

响应计数:

lastSec   lastMin    lastHour    today
=======================================
1 5 22 45

Meter methods获取最后一秒、一分钟、十五个速率。但是如何获取过去一小时和今天的数据?

以下尝试:

public class ReportMetrics {

static final MetricRegistry metrics = new MetricRegistry();
static final Counter aReqCount = ReportMetrics.metrics.counter(name(AProcessor.class, "a-req-count"));
static final Counter aResCount = ReportMetrics.metrics.counter(name(AProcessor.class, "a-res-count"));

private static final AProcessor aProcessor = new AProcessor();

public static void main(String[] args) {
startReport();

for(int i=0; i<=5; i++){
//add
aProcessor.addJob();
wait5Seconds();

//take
arProcessor.takeJob();
wait5Seconds();
}

}

static void startReport() {
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.SECONDS);
}

static void wait5Seconds() {
try {
Thread.sleep(5*1000);
}
catch(InterruptedException e) {}
}

public long requestCount(){
ReportMetrics.metrics.aReqCount.getCount();
}

public long responseCount(){
ReportMetrics.metrics.aResCount.getCount();
}

public long pendingRequestCount(){
return requestCount() - responseCount();
}

}

class AProcessor {

public void addJob(){
ReportMetrics.metrics.aReqCount.inc();
}

public Object takeJob(){
ReportMetrics.metrics.aResCount.inc();
}
}

最佳答案

要总结或计算使用 counter.inc 报告的计数器的每个任意时间间隔的计数(总计):

hitcount(perSecond(AProcessor.a-req-count.count), '1hour')

hitcount(perSecond(AProcessor.a-res-count.count), '1day')

据我所知,它里面有所有的黑魔法。包括但不限于summarize(scaleToSeconds(nonNegativeDerivative(your.count),1), '1day')并且还应该根据落入所选聚合区间的碳保留期(一个或多个)进行缩放。

关于java - Codahale 指标计数器每天重置并计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39198572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com