about summary refs log tree commit diff
path: root/MatrixContentFilter/Services/MatrixContentFilterMetrics.cs
blob: ff88cadea1cc58b3d94d4caa6a37cd8a6ffe8029 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System.Collections.Frozen;
using System.Diagnostics.Metrics;

namespace MatrixContentFilter.Services;

public class MatrixContentFilterMetrics {
    private readonly Meter meter = new Meter("MatrixContentFilter");
    private FrozenDictionary<string, Counter<int>> _counters = FrozenDictionary<string, Counter<int>>.Empty;

    public void Increment(string counter, int value = 1) {
        if(!_counters.TryGetValue(counter, out var c)) {
            c = meter.CreateCounter<int>(counter);
            _counters = _counters.Concat([new KeyValuePair<string, Counter<int>>(counter, c)]).ToFrozenDictionary();
        }
    }
}