22
22
import java .util .HashSet ;
23
23
import java .util .Iterator ;
24
24
import java .util .List ;
25
+ import java .util .Locale ;
25
26
import java .util .Map ;
26
27
import java .util .Optional ;
27
28
import java .util .Set ;
43
44
import io .helidon .metrics .api .DistributionSummary ;
44
45
import io .helidon .metrics .api .FunctionalCounter ;
45
46
import io .helidon .metrics .api .Gauge ;
47
+ import io .helidon .metrics .api .HistogramSnapshot ;
46
48
import io .helidon .metrics .api .Meter ;
47
49
import io .helidon .metrics .api .MeterRegistry ;
48
50
import io .helidon .metrics .api .MeterRegistryFormatter ;
@@ -451,14 +453,16 @@ protected void apply(JsonObjectBuilder builder) {
451
453
sameNameBuilder .add (valueId ("count" , childID ), typedChild .count ());
452
454
} else if (child instanceof DistributionSummary typedChild ) {
453
455
sameNameBuilder .add (valueId ("count" , childID ), typedChild .count ());
454
- sameNameBuilder .add (valueId ("max" , childID ), typedChild .snapshot (). max ());
455
- sameNameBuilder .add (valueId ("mean" , childID ), typedChild .snapshot (). mean ());
456
+ sameNameBuilder .add (valueId ("max" , childID ), typedChild .max ());
457
+ sameNameBuilder .add (valueId ("mean" , childID ), typedChild .mean ());
456
458
sameNameBuilder .add (valueId ("total" , childID ), typedChild .totalAmount ());
459
+ addDetails (typedChild .snapshot (), childID , null );
457
460
} else if (child instanceof Timer typedChild ) {
458
461
sameNameBuilder .add (valueId ("count" , childID ), typedChild .count ());
459
- sameNameBuilder .add (valueId ("elapsedTime" , childID ), typedChild .totalTime (TimeUnit .SECONDS ));
460
462
sameNameBuilder .add (valueId ("max" , childID ), typedChild .max (TimeUnit .SECONDS ));
461
463
sameNameBuilder .add (valueId ("mean" , childID ), typedChild .mean (TimeUnit .SECONDS ));
464
+ sameNameBuilder .add (valueId ("elapsedTime" , childID ), typedChild .totalTime (TimeUnit .SECONDS ));
465
+ addDetails (typedChild .snapshot (), childID , timeUnit (typedChild ));
462
466
} else if (child instanceof FunctionalCounter typedChild ) {
463
467
sameNameBuilder .add (valueId ("count" , childID ), typedChild .count ());
464
468
} else if (child instanceof Gauge typedChild ) {
@@ -471,6 +475,42 @@ protected void apply(JsonObjectBuilder builder) {
471
475
builder .add (meterId .name (), sameNameBuilder );
472
476
}
473
477
478
+ private void addDetails (HistogramSnapshot snapshot , Meter .Id childId , TimeUnit timeUnit ) {
479
+ snapshot .percentileValues ().forEach (vap ->
480
+ sameNameBuilder
481
+ .add (valueId (percentileName (vap .percentile ()),
482
+ childId ),
483
+ timeUnit != null
484
+ ? vap .value (timeUnit )
485
+ : vap .value ()));
486
+ snapshot .histogramCounts ().forEach (bucket ->
487
+ sameNameBuilder
488
+ .add (valueId (bucketName (timeUnit != null
489
+ ? bucket .boundary (timeUnit )
490
+ : bucket .boundary ()),
491
+ childId ),
492
+ bucket .count ()));
493
+ }
494
+
495
+ private static String percentileName (double percentile ) {
496
+ return "p" + percentile ;
497
+ }
498
+
499
+ private static String bucketName (double boundary ) {
500
+ return "b" + boundary ;
501
+ }
502
+
503
+ private static TimeUnit timeUnit (Timer timer ) {
504
+ if (timer .baseUnit ().isPresent ()) {
505
+ try {
506
+ return TimeUnit .valueOf (timer .baseUnit ().get ().toUpperCase (Locale .getDefault ()));
507
+ } catch (IllegalArgumentException ex ) {
508
+ return TimeUnit .SECONDS ;
509
+ }
510
+ }
511
+ return TimeUnit .SECONDS ;
512
+ }
513
+
474
514
private static String valueId (String valueName , Meter .Id meterId ) {
475
515
return valueName + tagsPortion (meterId );
476
516
}
0 commit comments