Skip to content

Commit 8dd98fa

Browse files
committed
Initial Metrics implementations
1 parent 8ce9e4d commit 8dd98fa

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
@@ -350,6 +350,10 @@ internal string GetStormLog()
350350
internal void IncrementOpCount()
351351
{
352352
Interlocked.Increment(ref operationCount);
353+
354+
#if NET6_0_OR_GREATER
355+
RedisMetrics.Instance.IncrementOpCount(Name);
356+
#endif
353357
}
354358

355359
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)