@@ -9,32 +9,37 @@ internal sealed class RedisMetrics
9
9
{
10
10
private readonly Meter _meter ;
11
11
private readonly Counter < long > _operationCount ;
12
- //private readonly Counter<long> _completedAsynchronously;
13
- //private readonly Counter<long> _completedSynchronously;
14
- //private readonly Counter<long> _failedSynchronously;
12
+ private readonly Counter < long > _completedAsynchronously ;
13
+ private readonly Counter < long > _completedSynchronously ;
14
+ private readonly Counter < long > _failedAsynchronously ;
15
+ private readonly Counter < long > _failedSynchronously ;
15
16
private readonly Counter < long > _nonPreferredEndpointCount ;
16
17
17
18
public static readonly RedisMetrics Instance = new RedisMetrics ( ) ;
18
19
19
- public RedisMetrics ( )
20
+ private RedisMetrics ( )
20
21
{
21
22
_meter = new Meter ( "StackExchange.Redis" ) ;
22
23
23
24
_operationCount = _meter . CreateCounter < long > (
24
25
"redis-operation-count" ,
25
26
description : "The number of operations performed." ) ;
26
27
27
- // _completedAsynchronously = _meter.CreateCounter<long>(
28
- // "redis-completed-asynchronously",
29
- // description: "The number of operations that have been completed asynchronously.");
28
+ _completedAsynchronously = _meter . CreateCounter < long > (
29
+ "redis-completed-asynchronously" ,
30
+ description : "The number of operations that have been completed asynchronously." ) ;
30
31
31
- // _completedSynchronously = _meter.CreateCounter<long>(
32
- // "redis-completed-synchronously",
33
- // description: "The number of operations that have been completed synchronously.");
32
+ _completedSynchronously = _meter . CreateCounter < long > (
33
+ "redis-completed-synchronously" ,
34
+ description : "The number of operations that have been completed synchronously." ) ;
34
35
35
- //_failedSynchronously = _meter.CreateCounter<long>(
36
- // "redis-failed-synchronously",
37
- // description: "The number of operations that failed to complete asynchronously.");
36
+ _failedAsynchronously = _meter . CreateCounter < long > (
37
+ "redis-failed-asynchronously" ,
38
+ description : "The number of operations that failed to complete asynchronously." ) ;
39
+
40
+ _failedSynchronously = _meter . CreateCounter < long > (
41
+ "redis-failed-synchronously" ,
42
+ description : "The number of operations that failed to complete synchronously." ) ;
38
43
39
44
_nonPreferredEndpointCount = _meter . CreateCounter < long > (
40
45
"redis-non-preferred-endpoint-count" ,
@@ -50,6 +55,27 @@ public void IncrementOperationCount(string endpoint)
50
55
}
51
56
}
52
57
58
+ public void OnMessageComplete ( IResultBox ? result )
59
+ {
60
+ if ( result is not null &&
61
+ ( _completedAsynchronously . Enabled ||
62
+ _completedSynchronously . Enabled ||
63
+ _failedAsynchronously . Enabled ||
64
+ _failedSynchronously . Enabled ) )
65
+ {
66
+ Counter < long > counter = ( result . IsFaulted , result . IsAsync ) switch
67
+ {
68
+ ( false , true ) => _completedAsynchronously ,
69
+ ( false , false ) => _completedSynchronously ,
70
+ ( true , true ) => _failedAsynchronously ,
71
+ ( true , false ) => _failedSynchronously ,
72
+ } ;
73
+
74
+ // TODO: can we pass endpoint here?
75
+ counter . Add ( 1 ) ;
76
+ }
77
+ }
78
+
53
79
public void IncrementNonPreferredEndpointCount ( string endpoint )
54
80
{
55
81
if ( _nonPreferredEndpointCount . Enabled )
0 commit comments