16
16
17
17
package net .devh .boot .grpc .client .metrics ;
18
18
19
+ import java .time .Duration ;
20
+
19
21
import io .micrometer .core .instrument .Counter ;
22
+ import io .micrometer .core .instrument .DistributionSummary ;
20
23
import io .micrometer .core .instrument .MeterRegistry ;
24
+ import io .micrometer .core .instrument .Timer ;
25
+ import io .micrometer .core .instrument .binder .BaseUnits ;
21
26
22
27
/*
23
28
* The instruments used to record metrics on client.
@@ -27,21 +32,70 @@ public final class MetricsClientInstruments {
27
32
private MetricsClientInstruments () {}
28
33
29
34
/*
30
- * This is a client side metric defined in gRFC <a
31
- * href="https://github.com/grpc/proposal/blob/master/A66-otel-stats.md">A66</a>. Please note that this is the name
32
- * used for instrumentation and can be changed by exporters in an unpredictable manner depending on the destination.
35
+ * Client side metrics defined in gRFC <a
36
+ * href="https://github.com/grpc/proposal/blob/master/A66-otel-stats.md">A66</a>. Please note that these are the
37
+ * names used for instrumentation and can be changed by exporters in an unpredictable manner depending on the
38
+ * destination.
33
39
*/
34
40
private static final String CLIENT_ATTEMPT_STARTED = "grpc.client.attempt.started" ;
41
+ private static final String CLIENT_ATTEMPT_SENT_COMPRESSED_MESSAGE_SIZE =
42
+ "grpc.client.attempt.sent_total_compressed_message_size" ;
43
+ private static final String CLIENT_ATTEMPT_RECEIVED_COMPRESSED_MESSAGE_SIZE =
44
+ "grpc.client.attempt.rcvd_total_compressed_message_size" ;
45
+ private static final String CLIENT_ATTEMPT_DURATION =
46
+ "grpc.client.attempt.duration" ;
47
+ private static final String CLIENT_CALL_DURATION =
48
+ "grpc.client.call.duration" ;
49
+ private static final double [] DEFAULT_SIZE_BUCKETS =
50
+ new double [] {1024d , 2048d , 4096d , 16384d , 65536d , 262144d , 1048576d ,
51
+ 4194304d , 16777216d , 67108864d , 268435456d , 1073741824d , 4294967296d };
52
+ private static final Duration [] DEFAULT_LATENCY_BUCKETS =
53
+ new Duration [] {Duration .ofNanos (10000 ), Duration .ofNanos (50000 ), Duration .ofNanos (100000 ),
54
+ Duration .ofNanos (300000 ), Duration .ofNanos (600000 ), Duration .ofNanos (800000 ),
55
+ Duration .ofMillis (1 ), Duration .ofMillis (2 ), Duration .ofMillis (3 ), Duration .ofMillis (4 ),
56
+ Duration .ofMillis (5 ), Duration .ofMillis (6 ), Duration .ofMillis (8 ), Duration .ofMillis (10 ),
57
+ Duration .ofMillis (13 ), Duration .ofMillis (16 ), Duration .ofMillis (20 ), Duration .ofMillis (25 ),
58
+ Duration .ofMillis (30 ), Duration .ofMillis (40 ), Duration .ofMillis (50 ), Duration .ofMillis (65 ),
59
+ Duration .ofMillis (80 ), Duration .ofMillis (100 ), Duration .ofMillis (130 ), Duration .ofMillis (160 ),
60
+ Duration .ofMillis (200 ), Duration .ofMillis (250 ), Duration .ofMillis (300 ), Duration .ofMillis (400 ),
61
+ Duration .ofMillis (500 ), Duration .ofMillis (650 ), Duration .ofMillis (800 ),
62
+ Duration .ofSeconds (1 ), Duration .ofSeconds (2 ), Duration .ofSeconds (5 ), Duration .ofSeconds (10 ),
63
+ Duration .ofSeconds (20 ), Duration .ofSeconds (50 ), Duration .ofSeconds (100 )};
35
64
36
- static MetricsMeters newClientMetricsMeters (MeterRegistry registry ) {
37
- MetricsMeters .Builder builder = MetricsMeters .newBuilder ();
65
+ static MetricsClientMeters newClientMetricsMeters (MeterRegistry registry ) {
66
+ MetricsClientMeters .Builder builder = MetricsClientMeters .newBuilder ();
38
67
39
68
builder .setAttemptCounter (Counter .builder (CLIENT_ATTEMPT_STARTED )
40
69
.description (
41
70
"The total number of RPC attempts started from the client side, including "
42
71
+ "those that have not completed." )
43
72
.baseUnit ("attempt" )
44
73
.withRegistry (registry ));
74
+
75
+ builder .setSentMessageSizeDistribution (DistributionSummary .builder (
76
+ CLIENT_ATTEMPT_SENT_COMPRESSED_MESSAGE_SIZE )
77
+ .description ("Compressed message bytes sent per client call attempt" )
78
+ .baseUnit (BaseUnits .BYTES )
79
+ .serviceLevelObjectives (DEFAULT_SIZE_BUCKETS )
80
+ .withRegistry (registry ));
81
+
82
+ builder .setReceivedMessageSizeDistribution (DistributionSummary .builder (
83
+ CLIENT_ATTEMPT_RECEIVED_COMPRESSED_MESSAGE_SIZE )
84
+ .description ("Compressed message bytes received per call attempt" )
85
+ .baseUnit (BaseUnits .BYTES )
86
+ .serviceLevelObjectives (DEFAULT_SIZE_BUCKETS )
87
+ .withRegistry (registry ));
88
+
89
+ builder .setClientAttemptDuration (Timer .builder (CLIENT_ATTEMPT_DURATION )
90
+ .description ("Time taken to complete a client call attempt" )
91
+ .serviceLevelObjectives (DEFAULT_LATENCY_BUCKETS )
92
+ .withRegistry (registry ));
93
+
94
+ builder .setClientCallDuration (Timer .builder (CLIENT_CALL_DURATION )
95
+ .description ("Time taken by gRPC to complete an RPC from application's perspective" )
96
+ .serviceLevelObjectives (DEFAULT_LATENCY_BUCKETS )
97
+ .withRegistry (registry ));
98
+
45
99
return builder .build ();
46
100
}
47
101
0 commit comments