-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathDogstatsd.cs
More file actions
302 lines (274 loc) · 17.4 KB
/
Dogstatsd.cs
File metadata and controls
302 lines (274 loc) · 17.4 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
using System;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("StatsdClient.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009558fd81ea0e330858198ae6c860c0c9fd2d9df3e5f2069434649e4ec61c9ceb9744d2a3fd82518d90abb5cbcefb6292e9d227d5854bd07dbd8884d129350c95c7742d499dfc4961223b35326e203c5924e413a2385a7aa7c704432e9101bb946da201977df2b992c25d0fb77645c1ac5bc29cde7bc8e5d054b78bd9c6727497")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: InternalsVisibleTo("StatsdClient.Benchmarks,PublicKey=00240000048000009400000006020000002400005253413100040000010001009558fd81ea0e330858198ae6c860c0c9fd2d9df3e5f2069434649e4ec61c9ceb9744d2a3fd82518d90abb5cbcefb6292e9d227d5854bd07dbd8884d129350c95c7742d499dfc4961223b35326e203c5924e413a2385a7aa7c704432e9101bb946da201977df2b992c25d0fb77645c1ac5bc29cde7bc8e5d054b78bd9c6727497")]
namespace StatsdClient
{
/// <summary>
/// The status of the service check.
/// </summary>
public enum Status
{
/// <summary>
/// Status OK
/// </summary>
OK = 0,
/// <summary>
/// Status Warning
/// </summary>
WARNING = 1,
/// <summary>
/// Status Critical
/// </summary>
CRITICAL = 2,
/// <summary>
/// Status Unknown
/// </summary>
UNKNOWN = 3,
}
/// <summary>
/// The available options for Tag Cardinality.
/// </summary>
public enum Cardinality
{
/// <summary>
/// Cardinality None
/// </summary>
None,
/// <summary>
/// Cardinality Low
/// </summary>
Low,
/// <summary>
/// Cardinality Orchestrator
/// </summary>
Orchestrator,
/// <summary>
/// Cardinality High
/// </summary>
High,
}
/// <summary>
/// DogStatsd is a collection of static methods that provide the same feature as DogStatsdService.
/// </summary>
public static class DogStatsd
{
private static readonly DogStatsdService _dogStatsdService = new DogStatsdService();
/// <summary>
/// Gets the telemetry counters
/// </summary>
/// <value>The telemetry counters.</value>
public static ITelemetryCounters TelemetryCounters => _dogStatsdService.TelemetryCounters;
/// <summary>
/// Configures the instance.
/// Must be called before any other methods.
/// </summary>
/// <param name="config">The value of the config.</param>
/// <param name="optionalExceptionHandler">The handler called when an error occurs."</param>
/// <returns>Return true if the operation succeed, false otherwise. If this function fails,
/// other methods in this class do nothing and an error is reported to <paramref name="optionalExceptionHandler"/>.</returns>
public static bool Configure(StatsdConfig config, Action<Exception> optionalExceptionHandler = null)
{
return _dogStatsdService.Configure(config, optionalExceptionHandler);
}
/// <summary>
/// Records an event.
/// </summary>
/// <param name="title">The title of the event.</param>
/// <param name="text">The text body of the event.</param>
/// <param name="alertType">error, warning, success, or info (defaults to info).</param>
/// <param name="aggregationKey">A key to use for aggregating events.</param>
/// <param name="sourceType">The source type name.</param>
/// <param name="dateHappened">The epoch timestamp for the event (defaults to the current time from the DogStatsD server).</param>
/// <param name="priority">Specifies the priority of the event (normal or low).</param>
/// <param name="hostname">The name of the host.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this event.</param>
public static void Event(
string title,
string text,
string alertType = null,
string aggregationKey = null,
string sourceType = null,
int? dateHappened = null,
string priority = null,
string hostname = null,
string[] tags = null,
Cardinality? cardinality = null)
=>
_dogStatsdService.Event(
title: title,
text: text,
alertType: alertType,
aggregationKey: aggregationKey,
sourceType: sourceType,
dateHappened: dateHappened,
priority: priority,
hostname: hostname,
cardinality: cardinality,
tags: tags);
/// <summary>
/// Adjusts the specified counter by a given delta.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">A given delta.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="timestamp">BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Counter(string statName, double value, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null, Cardinality? cardinality = null) =>
_dogStatsdService.Counter(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp: timestamp, cardinality: cardinality);
/// <summary>
/// Increments the specified counter.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The amount of increment.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="timestamp">BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null, Cardinality? cardinality = null) =>
_dogStatsdService.Increment(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp: timestamp, cardinality: cardinality);
/// <summary>
/// Decrements the specified counter.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The amount of decrement.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="timestamp">BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null, Cardinality? cardinality = null) =>
_dogStatsdService.Decrement(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp: timestamp, cardinality: cardinality);
/// <summary>
/// Records the latest fixed value for the specified named gauge.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The value of the gauge.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="timestamp">BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the gauge has been seen with the given value. This value is sent without any aggregation.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Gauge(string statName, double value, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null, Cardinality? cardinality = null) =>
_dogStatsdService.Gauge(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp, cardinality: cardinality);
/// <summary>
/// Records a value for the specified named histogram.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The value of the histogram.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Histogram(string statName, double value, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Histogram(statName: statName, value: value, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records a value for the specified named distribution.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The value of the distribution.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Distribution(string statName, double value, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Distribution(statName: statName, value: value, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records a value for the specified set.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The value to set.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
/// <typeparam name="T">The type of the value.</typeparam>
public static void Set<T>(string statName, T value, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Set<T>(statName: statName, value: value, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records a value for the specified set.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The value to set.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Set(string statName, string value, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Set(statName: statName, value: value, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records an execution time in milliseconds.
/// </summary>
/// <param name="statName">The name of the metric.</param>
/// <param name="value">The time in millisecond.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Timer(string statName, double value, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Timer(statName: statName, value: value, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Creates a timer that records the execution time until Dispose is called on the returned value.
/// </summary>
/// <param name="name">The name of the metric.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
/// <returns>A disposable object that records the execution time until Dispose is called.</returns>
public static IDisposable StartTimer(string name, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.StartTimer(name: name, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records an execution time for the given action.
/// </summary>
/// <param name="action">The given action.</param>
/// <param name="statName">The name of the metric.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
public static void Time(Action action, string statName, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Time(action: action, statName: statName, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records an execution time for the given function.
/// </summary>
/// <param name="func">The given function.</param>
/// <param name="statName">The name of the metric.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="cardinality">The cardinality for tags added to this metric.</param>
/// <typeparam name="T">The type of the returned value of <paramref name="func"/>.</typeparam>
/// <returns>The returned value of <paramref name="func"/>.</returns>
public static T Time<T>(Func<T> func, string statName, double sampleRate = 1.0, string[] tags = null, Cardinality? cardinality = null) =>
_dogStatsdService.Time<T>(func: func, statName: statName, sampleRate: sampleRate, tags: tags, cardinality: cardinality);
/// <summary>
/// Records a run status for the specified named service check.
/// </summary>
/// <param name="name">The name of the service check.</param>
/// <param name="status">A constant describing the service status.</param>
/// <param name="timestamp">The epoch timestamp for the service check (defaults to the current time from the DogStatsD server).</param>
/// <param name="hostname">The hostname to associate with the service check.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
/// <param name="message">Additional information or a description of why the status occurred.</param>
/// <param name="cardinality">The cardinality for tags added to this service check.</param>
public static void ServiceCheck(
string name,
Status status,
int? timestamp = null,
string hostname = null,
string[] tags = null,
string message = null,
Cardinality? cardinality = null) =>
_dogStatsdService.ServiceCheck(name, status, timestamp, hostname, tags, message, cardinality);
/// <summary>
/// Flushes all metrics.
/// </summary>
/// <param name="flushTelemetry">The value indicating whether the telemetry must be flushed.</param>
public static void Flush(bool flushTelemetry = true)
{
_dogStatsdService.Flush(flushTelemetry);
}
/// <summary>
/// Disposes the instance of DogStatsdService.
/// Flushes all metrics.
/// </summary>
public static void Dispose()
{
_dogStatsdService.Dispose();
}
}
}