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