forked from JoeShook/ZiggyCreatures.FusionCache.Metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FusionMetricsRegistry.cs
180 lines (166 loc) · 7.38 KB
/
FusionMetricsRegistry.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#region (c) 2021 Joseph Shook. All rights reserved.
// /*
// Authors:
// Joseph Shook [email protected]
//
// See LICENSE in the project root for license information.
// */
#endregion
using App.Metrics;
using App.Metrics.Counter;
using App.Metrics.Gauge;
using ZiggyCreatures.Caching.Fusion.Plugins.Metrics.Core;
namespace ZiggyCreatures.Caching.Fusion.Plugins.Metrics.AppMetrics
{
/// <summary>
/// Define FusionCache metrics
/// In time series database the <see cref="MetricValueOptionsBase.Context"/> will be prefixed to the
/// <see cref="ISemanticConventions.MeasurementName"/> or see cref="ISemanticConventions.GaugeName"/>
/// </summary>
public class FusionMetricsRegistry
{
/// <summary>
/// Cache hit counter
/// </summary>
public static CounterOptions CacheHitCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheHitTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheHitTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache miss counter. When a cache is not found in local cache
/// </summary>
public static CounterOptions CacheMissCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheMissTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheMissTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache set counter. When a cache is written to local cache
/// </summary>
public static CounterOptions CacheSetCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheSetTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheSetTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache stale hit counter. Cache failed to complete within soft timeout period.
/// </summary>
public static CounterOptions CacheStaleHitCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheStaleHitTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheStaleHitTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache refresh in background.
/// </summary>
public static CounterOptions CacheBackgroundRefreshed(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheBackgroundRefreshedTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheBackgroundRefreshedTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache refresh in background failed.
/// </summary>
public static CounterOptions CacheBackgroundRefreshError(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheBackgroundFailedRefreshedTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheBackgroundFailedRefreshedTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Generic cache factory error.
/// </summary>
public static CounterOptions CacheFactoryError(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheCacheFactoryErrorTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheCacheFactoryErrorTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache factory synthetic timeout
/// </summary>
public static CounterOptions CacheFactorySyntheticTimeout(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheFactorySyntheticTimeoutTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheFactorySyntheticTimeoutTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache Fail-Safe activation
/// </summary>
public static CounterOptions CacheFailSafeActivate(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheFailSafeActivateTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheFailSafeActivateTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache expired counter
/// </summary>
public static CounterOptions CacheExpireCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheExpiredEvictTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheExpiredEvictTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache eviction from capacity limit
/// </summary>
public static CounterOptions CacheCapacityCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheCapacityEvictTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheCapacityEvictTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache item removed counter
/// </summary>
public static CounterOptions CacheRemoveCounter(ISemanticConventions conventions) => new CounterOptions
{
Context = conventions.MeasurementName,
Name = conventions.CacheRemovedTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheRemovedTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = true
};
/// <summary>
/// Cache item count. Tracked by add and remove counters.
/// </summary>
public static GaugeOptions CacheItemGauge(ISemanticConventions conventions) => new GaugeOptions
{
Context = conventions.GaugeName,
Name = conventions.CacheItemCountTagValue,
Tags = new MetricTags(conventions.CacheEventTagName, conventions.CacheItemCountTagValue),
MeasurementUnit = Unit.Events,
ResetOnReporting = false,
};
}
}