@@ -17,7 +17,11 @@ public static void main(String[] args) throws InterruptedException {
1717 // 注册需要收集指标数据的Flower
1818 MetricPersistencer .registerFlower ("test-resource" , flowHelper .getFlow (FlowType .Minute ));
1919 new Thread (() -> {
20+ int i = 0 ;
2021 while (!Thread .interrupted ()) {
22+ if (i ++ >= 100 ) {
23+ break ;
24+ }
2125 try {
2226 Thread .sleep (1 );
2327 flowHelper .incrSuccess (1 );
@@ -38,23 +42,23 @@ public static void main(String[] args) throws InterruptedException {
3842 System .out .println ("最小请求耗时:" + flower .minRt ());
3943 System .out .println ("平均请求成功数:" + flower .successAvg ());
4044 System .out .println ("平均请求异常数:" + flower .exceptionAvg ());
41- try {
42- Thread .sleep (10000 );
43- } catch (InterruptedException e ) {
44- e .printStackTrace ();
45- }
4645 System .out .println ();
4746 List <WindowWrap <MetricBucket >> buckets = flower .windows ();
4847 for (WindowWrap <MetricBucket > bucket : buckets ) {
4948 System .out .print ("开始时间戳:" + bucket .windowStart () + "\t " );
5049 System .out .print ("成功数:" + bucket .value ().success () + "\t " );
5150 System .out .print ("失败数:" + bucket .value ().exception () + "\t " );
52- System .out .print ("平均耗时:" + (bucket .value ().rt () / bucket .value ().success ()) + "\t " );
53- System .out .print ("最大数 :" + bucket .value ().maxRt () + "\t " );
54- System .out .print ("最小数 :" + bucket .value ().minRt () + "\t " );
51+ System .out .print ("平均耗时:" + (bucket .value ().success () > 0 ? ( bucket . value (). rt () / bucket .value ().success ()) : 0 ) + "\t " );
52+ System .out .print ("最大耗时 :" + bucket .value ().maxRt () + "\t " );
53+ System .out .print ("最小耗时 :" + bucket .value ().minRt () + "\t " );
5554 System .out .println ();
5655 }
5756 System .out .println ("======================================================" );
57+ try {
58+ Thread .sleep (1000 * 60 );
59+ } catch (InterruptedException e ) {
60+ e .printStackTrace ();
61+ }
5862 }
5963 }).start ();
6064 Thread .sleep (Integer .MAX_VALUE );
0 commit comments