-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathMetrics.cs
42 lines (35 loc) · 1.15 KB
/
Metrics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace ServiceControl.Infrastructure.Metrics
{
using System.Collections.Generic;
using System.Linq;
public class Metrics
{
readonly Dictionary<string, Counter> counters = [];
readonly Dictionary<string, Meter> meters = [];
public bool Enabled { get; set; }
public Counter GetCounter(string name)
{
if (!counters.TryGetValue(name, out var meter))
{
meter = new Counter(name, Enabled);
counters[name] = meter;
}
return meter;
}
public Meter GetMeter(string name, float scale = 1)
{
if (!meters.TryGetValue(name, out var meter))
{
meter = new Meter(name, Enabled, scale);
meters[name] = meter;
}
return meter;
}
public IReadOnlyCollection<MeterValues> GetMeterValues()
{
var counterValues = counters.Values.Select(x => x.GetValues());
var meterValues = meters.Values.Select(x => x.GetValues());
return counterValues.Concat(meterValues).ToArray();
}
}
}