Skip to content

Commit 5990f8e

Browse files
committed
Initial Metrics implementations
1 parent f22e43e commit 5990f8e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/StackExchange.Redis/PhysicalBridge.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ internal string GetStormLog()
348348
internal void IncrementOpCount()
349349
{
350350
Interlocked.Increment(ref operationCount);
351+
352+
#if NET6_0_OR_GREATER
353+
RedisMetrics.Instance.IncrementOpCount(Name);
354+
#endif
351355
}
352356

353357
internal void KeepAlive()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#if NET6_0_OR_GREATER
2+
3+
using System.Collections.Generic;
4+
using System.Diagnostics.Metrics;
5+
6+
namespace StackExchange.Redis;
7+
8+
internal sealed class RedisMetrics
9+
{
10+
private readonly Meter _meter;
11+
private readonly Counter<long> _operationCount;
12+
//private readonly Counter<long> _completedAsynchronously;
13+
//private readonly Counter<long> _completedSynchronously;
14+
//private readonly Counter<long> _failedSynchronously;
15+
16+
public static readonly RedisMetrics Instance = new RedisMetrics();
17+
18+
public RedisMetrics()
19+
{
20+
_meter = new Meter("StackExchange.Redis");
21+
22+
_operationCount = _meter.CreateCounter<long>(
23+
"operation-count",
24+
description: "The number of operations performed.");
25+
26+
//_completedAsynchronously = _meter.CreateCounter<long>(
27+
// "completed-asynchronously",
28+
// description: "The number of operations that have been completed asynchronously.");
29+
30+
//_completedSynchronously = _meter.CreateCounter<long>(
31+
// "completed-synchronously",
32+
// description: "The number of operations that have been completed synchronously.");
33+
34+
//_failedSynchronously = _meter.CreateCounter<long>(
35+
// "failed-synchronously",
36+
// description: "The number of operations that failed to complete asynchronously.");
37+
}
38+
39+
public void IncrementOpCount(string connectionName)
40+
{
41+
if (_operationCount.Enabled)
42+
{
43+
_operationCount.Add(1,
44+
new KeyValuePair<string, object?>("connection-name", connectionName));
45+
}
46+
}
47+
}
48+
49+
#endif

0 commit comments

Comments
 (0)