/
MetricNames.cs
1111 lines (878 loc) · 53.2 KB
/
MetricNames.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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
using NewRelic.Agent.Core.AgentHealth;
using NewRelic.Agent.Core.Samplers;
using NewRelic.Agent.Core.Transformers.TransactionTransformer;
using NewRelic.Agent.Extensions.Providers.Wrapper;
using NewRelic.Core;
using NewRelic.Parsing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace NewRelic.Agent.Core.Metric
{
/// <summary>
/// This holds a representation of a metric name. It is used to defer string concatenation objects
/// to a later time. For instance, when aggregating a transactions metrics we aggregate the same metric name
/// over and over. Rather than computing the full string name for the metric we can use this class as the key,
/// aggregate all the data under a single MetricName key, then generate the metric string.
///
/// Subclasses of this class are not designed to implement equality in a perfect way. For instance, a
/// MetricName created with "One/Two" will not equal one created with ["One, Two"] even though the values
/// returned by ToString() do in fact equal. This should not be an issue because we generate MetricNames
/// through very controlled paths and we should not have any instances in which we generate the same
/// metric name string with MetricName instances created through calls to different MetricName.Create methods.
/// </summary>
public abstract class MetricName
{
private readonly int _hashCode;
private readonly int _length;
public static MetricName Create(string prefix, params string[] segments)
{
var hashCode = 31 + prefix.GetHashCode();
var length = segments.Length + prefix.Length;
foreach (var segment in segments)
{
hashCode = hashCode * 31 + segment.GetHashCode();
length += segment.Length;
}
return new MetricNameWithSegments(length, hashCode, prefix, segments);
}
public static MetricName Create(string prefix, params object[] segments)
{
var segmentStrings = new string[segments.Length];
for (var i = 0; i < segments.Length; i++)
{
segmentStrings[i] = segments[i]?.ToString() ?? string.Empty;
}
return Create(prefix, segmentStrings);
}
/// <summary>
/// Creates a MetricName from a string. We often use this constructor for "constant" style
/// metric names for which we want to perform all of the string concatenation once up front.
/// </summary>
public static MetricName Create(string name)
{
return new SimpleMetricName(name);
}
private MetricName(int length, int hashCode)
{
_length = length;
_hashCode = hashCode;
}
private class SimpleMetricName : MetricName
{
private readonly string _name;
public SimpleMetricName(string name) : base(name.Length, name.GetHashCode())
{
_name = name;
}
public override int GetHashCode()
{
return _hashCode;
}
public override bool Equals(object obj)
{
if (this == obj)
{
return true;
}
return obj is SimpleMetricName name && _name.Equals(name._name);
}
public override string ToString()
{
return _name;
}
}
private class MetricNameWithSegments : MetricName
{
private readonly string _prefix;
private readonly string[] _segments;
public MetricNameWithSegments(int length, int hashCode, string prefix, string[] segments) : base(length, hashCode)
{
_prefix = prefix;
_segments = segments;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
return obj is MetricNameWithSegments other &&
_length == other._length &&
_segments.Length == other._segments.Length &&
_prefix.Equals(other._prefix) &&
_segments.SequenceEqual(other._segments);
}
public override int GetHashCode()
{
return _hashCode;
}
public override string ToString()
{
var stringBuilder = new StringBuilder(_length).Append(_prefix);
foreach (var segment in _segments)
{
stringBuilder.Append(MetricNames.PathSeparatorChar).Append(segment);
}
return stringBuilder.ToString();
}
}
}
/// <summary>
/// An enumeration of standard metric names that the agent can generate.
/// </summary>
public static class MetricNames
{
public const string PathSeparator = "/";
public const string Controller = "DotNetController";
public const string Uri = "Uri";
public const string NormalizedUri = "NormalizedUri";
public const string All = "all";
public const string AllWeb = "allWeb";
public const string AllOther = "allOther";
public const string Custom = "Custom";
public const string OtherTransactionPrefix = "OtherTransaction";
public const string WebTransactionPrefix = "WebTransaction";
public const string SupportabilityPayloadsDroppedDueToMaxPayloadLimitPrefix = Supportability + PathSeparator + "DotNet/Collector" + PathSeparator + "MaxPayloadSizeLimit";
public static readonly char PathSeparatorChar = PathSeparator[0];
public static readonly char[] PathSeparatorCharArray = { PathSeparatorChar };
public static readonly MetricName Dispatcher = MetricName.Create("HttpDispatcher");
public static readonly MetricName RequestQueueTime = MetricName.Create("WebFrontend/QueueTime");
private static readonly Func<DatastoreVendor, MetricName> _databaseVendorAll;
private static readonly Func<DatastoreVendor, MetricName> _databaseVendorAllWeb;
private static readonly Func<DatastoreVendor, MetricName> _databaseVendorAllOther;
private static readonly Func<DatastoreVendor, Func<string, MetricName>> _databaseVendorOperations;
static MetricNames()
{
_databaseVendorAll = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + All));
_databaseVendorAllWeb = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + AllWeb));
_databaseVendorAllOther = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + AllOther));
var operations = new HashSet<string>(SqlParser.Operations);
operations.Add(DatastoreUnknownOperationName);
_databaseVendorOperations = GetEnumerationFunc<DatastoreVendor, Func<string, MetricName>>(
vendor =>
{
var dict = new Dictionary<string, MetricName>(operations.Count);
var metricNamePrefix = DatastoreOperation + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator;
foreach (var operation in operations)
{
dict[operation] = MetricName.Create(metricNamePrefix + operation);
}
return operation => (dict.TryGetValue(operation, out var name))
? name
: MetricName.Create(DatastoreOperation, EnumNameCache<DatastoreVendor>.GetName(vendor), operation);
});
}
public static MetricName GetCustom(string suffix)
{
return MetricName.Create(Custom, suffix);
}
/// <summary>
/// Returns a func that returns R for a given value of an enum E.
/// It uses the valueSupplier to compute the values of R and stores them
/// in an array.
/// </summary>
private static Func<TEnum, TResult> GetEnumerationFunc<TEnum, TResult>(Func<TEnum, TResult> valueSupplier)
{
var keys = Enum.GetValues(typeof(TEnum));
var array = new TResult[keys.Length];
// we can cast the enum to an int
foreach (var key in keys)
{
array[(int)key] = valueSupplier.Invoke((TEnum)key);
}
return key => array[(int)(object)key];
}
#region Apdex
public const string ApdexWeb = "Apdex";
public const string ApdexOther = "ApdexOther/Transaction";
// Apdex metrics spec: https://newrelic.atlassian.net/wiki/display/eng/OtherTransactions+as+Key+Transactions
public static readonly MetricName ApdexAll = MetricName.Create("ApdexAll");
public static readonly MetricName ApdexAllWeb = MetricName.Create("Apdex");
public static readonly MetricName ApdexAllOther = MetricName.Create("ApdexOther");
private static string Join(params string[] strings)
{
return string.Join(PathSeparator, strings);
}
public static MetricName GetApdexAllWebOrOther(bool isWebTransaction)
{
return isWebTransaction ? ApdexAllWeb : ApdexAllOther;
}
/// <summary>
/// Takes a transaction metric name and returns an appropriate apdex metric name. For example, WebTransaction/MVC/MyApp becomes Apdex/MVC/MyApp.
/// </summary>
/// <param name="transactionMetricName">The transaction metric name. Must be a valid transaction metric name.</param>
/// <returns>An apdex metric name.</returns>
public static string GetTransactionApdex(TransactionMetricName transactionMetricName)
{
var apdexPrefix = transactionMetricName.IsWebTransactionName ? ApdexWeb : ApdexOther;
return Join(apdexPrefix, transactionMetricName.UnPrefixedName);
}
#endregion Apdex
#region Errors
public const string Errors = "Errors";
public const string ErrorsExpected = "ErrorsExpected";
public static readonly MetricName ErrorsAll = MetricName.Create(Errors + PathSeparator + All);
public static readonly MetricName ErrorsAllWeb = MetricName.Create(Errors + PathSeparator + AllWeb);
public static readonly MetricName ErrorsAllOther = MetricName.Create(Errors + PathSeparator + AllOther);
public static readonly MetricName ErrorsExpectedAll = MetricName.Create(ErrorsExpected + PathSeparator + All);
public static MetricName GetErrorTransaction(string transactionMetricName)
{
return MetricName.Create(Errors, transactionMetricName);
}
#endregion Errors
#region DotNetInvocation
private const string DotNetInvocation = "DotNet";
public static MetricName GetDotNetInvocation(params string[] segments)
{
return MetricName.Create(DotNetInvocation, segments);
}
#endregion
#region Transactions
public enum WebTransactionType
{
Action,
Custom,
ASP,
MVC,
WCF,
WebAPI,
WebService,
MonoRail,
OpenRasta
}
public const string Message = "Message";
public static readonly MetricName WebTransactionAll = MetricName.Create(WebTransactionPrefix);
public static readonly MetricName OtherTransactionAll = MetricName.Create(OtherTransactionPrefix + PathSeparator + All);
#region Total time
public static readonly MetricName WebTransactionTotalTimeAll = MetricName.Create("WebTransactionTotalTime");
public static readonly MetricName OtherTransactionTotalTimeAll = MetricName.Create("OtherTransactionTotalTime");
public static MetricName TransactionTotalTime(TransactionMetricName transactionMetricName)
{
var prefix = transactionMetricName.IsWebTransactionName ? WebTransactionTotalTimeAll : OtherTransactionTotalTimeAll;
return MetricName.Create(prefix.ToString(), transactionMetricName.UnPrefixedName);
}
#endregion Total time
#region CPU time
private const string CpuTimePrefix = "CPU";
public const string WebTransactionCpuTimeAll = CpuTimePrefix + PathSeparator + WebTransactionPrefix;
public const string OtherTransactionCpuTimeAll = CpuTimePrefix + PathSeparator + OtherTransactionPrefix;
public static string TransactionCpuTime(TransactionMetricName transactionMetricName)
{
var prefix = transactionMetricName.IsWebTransactionName ? WebTransactionCpuTimeAll : OtherTransactionCpuTimeAll;
return Join(prefix, transactionMetricName.UnPrefixedName);
}
#endregion CPU time
#endregion
#region MessageBroker
public enum MessageBrokerDestinationType
{
Queue,
Topic,
TempQueue,
TempTopic
}
public enum MessageBrokerAction
{
Produce,
Consume,
Peek,
Purge,
}
public const string MessageBrokerPrefix = "MessageBroker";
public const string MessageBrokerNamed = "Named";
public const string MessageBrokerTemp = "Temp";
public const string Msmq = "MSMQ";
public static MetricName GetMessageBroker(MessageBrokerDestinationType type, MessageBrokerAction action,
string vendor, string queueName)
{
var normalizedType = NormalizeMessageBrokerDestinationTypeForMetricName(type);
return (queueName != null)
? MetricName.Create(MessageBrokerPrefix, vendor, normalizedType, action, MessageBrokerNamed, queueName)
: MetricName.Create(MessageBrokerPrefix, vendor, normalizedType, action, MessageBrokerTemp);
}
private static MessageBrokerDestinationType NormalizeMessageBrokerDestinationTypeForMetricName(
MessageBrokerDestinationType type)
{
if (type == MessageBrokerDestinationType.TempQueue)
{
return MessageBrokerDestinationType.Queue;
}
if (type == MessageBrokerDestinationType.TempTopic)
{
return MessageBrokerDestinationType.Topic;
}
return type;
}
#endregion MessageBroker
#region Datastore
private const string Datastore = "Datastore";
private const string DatastoreOperation = Datastore + PathSeparator + "operation";
private const string DatastoreStatement = Datastore + PathSeparator + "statement";
private const string DatastoreInstance = Datastore + PathSeparator + "instance";
public const string DatastoreUnknownOperationName = "other";
public static readonly MetricName DatastoreAll = MetricName.Create(Datastore + PathSeparator + All);
public static readonly MetricName DatastoreAllWeb = MetricName.Create(Datastore + PathSeparator + AllWeb);
public static readonly MetricName DatastoreAllOther = MetricName.Create(Datastore + PathSeparator + AllOther);
public static MetricName GetDatastoreVendorAll(this DatastoreVendor vendor)
{
return _databaseVendorAll.Invoke(vendor);
}
public static MetricName GetDatastoreVendorAllWeb(this DatastoreVendor vendor)
{
return _databaseVendorAllWeb.Invoke(vendor);
}
public static MetricName GetDatastoreVendorAllOther(this DatastoreVendor vendor)
{
return _databaseVendorAllOther.Invoke(vendor);
}
public static MetricName GetDatastoreOperation(this DatastoreVendor vendor, string operation = null)
{
operation = operation ?? DatastoreUnknownOperationName;
return _databaseVendorOperations.Invoke(vendor).Invoke(operation);
}
public static MetricName GetDatastoreStatement(DatastoreVendor vendor, string model,
string operation = null)
{
operation = operation ?? DatastoreUnknownOperationName;
return MetricName.Create(DatastoreStatement, EnumNameCache<DatastoreVendor>.GetName(vendor), model, operation);
}
public static MetricName GetDatastoreInstance(DatastoreVendor vendor, string host, string portPathOrId)
{
return MetricName.Create(DatastoreInstance, EnumNameCache<DatastoreVendor>.GetName(vendor), host, portPathOrId);
}
#endregion Datastore
#region External
private const string External = "External";
public static readonly MetricName ExternalAll = MetricName.Create(External + PathSeparator + All);
public static readonly MetricName ExternalAllWeb = MetricName.Create(External + PathSeparator + AllWeb);
public static readonly MetricName ExternalAllOther = MetricName.Create(External + PathSeparator + AllOther);
public static MetricName GetExternalHostRollup(string host)
{
return MetricName.Create(External, host, All);
}
public static MetricName GetExternalHost(string host, string library, string operation = null)
{
return operation != null
? MetricName.Create(External, host, library, operation)
: MetricName.Create(External, host, library);
}
public static MetricName GetExternalErrors(string server)
{
return MetricName.Create(External, server, "errors");
}
public static MetricName GetClientApplication(string crossProcessId)
{
return MetricName.Create("ClientApplication", crossProcessId, All);
}
public static MetricName GetExternalApp(string host, string crossProcessId)
{
return MetricName.Create("ExternalApp", host, crossProcessId, All);
}
public static MetricName GetExternalTransaction(string host, string crossProcessId, string transactionName)
{
return MetricName.Create("ExternalTransaction", host, crossProcessId, transactionName);
}
#endregion External
#region Supportability
private const string Supportability = "Supportability";
private const string SupportabilityDotnetPs = Supportability + PathSeparator + "Dotnet" + PathSeparator;
private const string SupportabilityPs = Supportability + PathSeparator;
private const string SupportabilityNetFrameworkVersionPs = SupportabilityDotnetPs + "NetFramework" + PathSeparator;
private const string SupportabilityNetCoreVersionPs = SupportabilityDotnetPs + "NetCore" + PathSeparator;
// Metrics
// NOTE: This metric is REQUIRED by the collector (it is used as a heartbeat)
public const string SupportabilityMetricHarvestTransmit = SupportabilityPs + "MetricHarvest" + PathSeparator + "transmit";
public static string GetSupportabilityAgentTimingMetric(string suffix)
{
return Supportability + PathSeparator + "AgentTiming" + PathSeparator + suffix;
}
// RUM
public const string SupportabilityRumHeaderRendered = SupportabilityPs + "RUM/Header";
public const string SupportabilityRumFooterRendered = SupportabilityPs + "RUM/Footer";
public const string SupportabilityHtmlPageRendered = SupportabilityPs + "RUM/HtmlPage";
// Thread Profiling
public const string SupportabilityThreadProfilingSampleCount = SupportabilityPs + "ThreadProfiling/SampleCount";
// Transaction Events
private const string SupportabilityTransactionEventsPs = SupportabilityPs + "AnalyticsEvents" + PathSeparator;
// Note: these two metrics are REQUIRED by APM (see https://source.datanerd.us/agents/agent-specs/pull/84)
public const string SupportabilityTransactionEventsSent = SupportabilityTransactionEventsPs + "TotalEventsSent";
public const string SupportabilityTransactionEventsSeen = SupportabilityTransactionEventsPs + "TotalEventsSeen";
public const string SupportabilityTransactionEventsCollected = SupportabilityTransactionEventsPs + "TotalEventsCollected";
public const string SupportabilityTransactionEventsRecollected = SupportabilityTransactionEventsPs + "TotalEventsRecollected";
public const string SupportabilityTransactionEventsReservoirResize = SupportabilityTransactionEventsPs + "TryResizeReservoir";
// Custom Events
private const string SupportabilityEventsPs = SupportabilityPs + "Events" + PathSeparator;
private const string SupportabilityCustomEventsPs = SupportabilityEventsPs + "Customer" + PathSeparator;
// Error Events
private const string SupportabilityErrorEventsPs = SupportabilityEventsPs + "TransactionError" + PathSeparator;
public const string SupportabilityErrorEventsSent = SupportabilityErrorEventsPs + "Sent";
public const string SupportabilityErrorEventsSeen = SupportabilityErrorEventsPs + "Seen";
// Note: Though not required by APM like the transaction event supportability metrics, these metrics should still be created to maintain consistency
public const string SupportabilityCustomEventsSent = SupportabilityCustomEventsPs + "Sent";
public const string SupportabilityCustomEventsSeen = SupportabilityCustomEventsPs + "Seen";
public const string SupportabilityCustomEventsCollected = SupportabilityCustomEventsPs + "TotalEventsCollected";
public const string SupportabilityCustomEventsRecollected = SupportabilityCustomEventsPs + "TotalEventsRecollected";
public const string SupportabilityCustomEventsReservoirResize = SupportabilityCustomEventsPs + "TryResizeReservoir";
// SQL Trace
private const string SupportabilitySqlTracesPs = SupportabilityPs + "SqlTraces" + PathSeparator;
public const string SupportabilitySqlTracesSent = SupportabilitySqlTracesPs + "TotalSqlTracesSent";
public const string SupportabilitySqlTracesRecollected = SupportabilitySqlTracesPs + "TotalSqlTracesRecollected";
public const string SupportabilityCachePrefix = SupportabilityPs + "Cache" + PathSeparator;
public static readonly MetricName SupportabilitySqlTracesCollected =
MetricName.Create(SupportabilitySqlTracesPs + "TotalSqlTracesCollected");
// Error Traces
private const string SupportabilityErrorTracesPs = SupportabilityPs + "Errors" + PathSeparator;
public const string SupportabilityErrorTracesSent = SupportabilityErrorTracesPs + "TotalErrorsSent";
public const string SupportabilityErrorTracesCollected = SupportabilityErrorTracesPs + "TotalErrorsCollected";
public const string SupportabilityErrorTracesRecollected = SupportabilityErrorTracesPs + "TotalErrorsRecollected";
// Transaction GarbageCollected
private const string SupportabilityTransactionBuilderGarbageCollectedPs =
SupportabilityPs + "TransactionBuilderGarbageCollected" + PathSeparator;
public const string SupportabilityTransactionBuilderGarbageCollectedAll =
SupportabilityTransactionBuilderGarbageCollectedPs + All;
//Faster Event Harvest
//These metric names are used in conjunction with GetSupportabilityName to build the full name
public const string SupportabilityEventHarvestPs = "EventHarvest" + PathSeparator;
public const string SupportabilityEventHarvestReportPeriod = SupportabilityEventHarvestPs + "ReportPeriod";
private const string SupportabilityEventHarvestHarvestLimit = PathSeparator + "HarvestLimit";
public const string SupportabilityEventHarvestErrorEventHarvestLimit = SupportabilityEventHarvestPs + "ErrorEventData" + SupportabilityEventHarvestHarvestLimit;
public const string SupportabilityEventHarvestCustomEventHarvestLimit = SupportabilityEventHarvestPs + "CustomEventData" + SupportabilityEventHarvestHarvestLimit;
public const string SupportabilityEventHarvestTransactionEventHarvestLimit = SupportabilityEventHarvestPs + "AnalyticEventData" + SupportabilityEventHarvestHarvestLimit;
public static string GetSupportabilityCATConditionMetricName(CATSupportabilityCondition condition)
{
if (_catMetricNames.TryGetValue(condition, out var metricName))
{
return metricName;
}
return SupportabilityCAT + EnumNameCache<CATSupportabilityCondition>.GetName(condition);
}
public static string GetSupportabilityName(string metricName)
{
if (metricName.StartsWith(Supportability + PathSeparator))
{
return metricName;
}
return Supportability + PathSeparator + metricName;
}
public static string GetSupportabilityDotnetFrameworkVersion(DotnetFrameworkVersion version)
{
return SupportabilityNetFrameworkVersionPs + version;
}
public static string GetSupportabilityDotnetCoreVersion(DotnetCoreVersion version)
{
return SupportabilityNetCoreVersionPs + version;
}
private const string SupportabilityAgentVersionPs = SupportabilityPs + "AgentVersion" + PathSeparator;
public static string GetSupportabilityAgentVersion(string version)
{
return SupportabilityAgentVersionPs + version;
}
public static string GetSupportabilityAgentVersionByHost(string host, string version)
{
return SupportabilityAgentVersionPs + host + PathSeparator + version;
}
private const string SupportabilityLibraryVersionPs = SupportabilityPs + "Library" + PathSeparator;
public static string GetSupportabilityLibraryVersion(string assemblyName, string assemblyVersion)
{
return SupportabilityLibraryVersionPs + assemblyName + PathSeparator + assemblyVersion;
}
// Utilization
private const string SupportabilityUtilizationPs = SupportabilityPs + "utilization" + PathSeparator;
private const string SupportabilityUtilizationBootIdError = SupportabilityUtilizationPs + "boot_id" + PathSeparator + "error";
private const string SupportabilityUtilizationKubernetesError = SupportabilityUtilizationPs + "kubernetes" + PathSeparator + "error";
private const string SupportabilityUtilizationAwsError = SupportabilityUtilizationPs + "aws" + PathSeparator + "error";
private const string SupportabilityUtilizationAzureError = SupportabilityUtilizationPs + "azure" + PathSeparator + "error";
private const string SupportabilityUtilizationGcpError = SupportabilityUtilizationPs + "gcp" + PathSeparator + "error";
private const string SupportabilityUtilizationPcfError = SupportabilityUtilizationPs + "pcf" + PathSeparator + "error";
public static string GetSupportabilityLinuxOs() => SupportabilityPs + "OS" + PathSeparator + "Linux";
public static string GetSupportabilityBootIdError() => SupportabilityUtilizationBootIdError;
public static string GetSupportabilityKubernetesUsabilityError() => SupportabilityUtilizationKubernetesError;
public static string GetSupportabilityAwsUsabilityError() => SupportabilityUtilizationAwsError;
public static string GetSupportabilityAzureUsabilityError() => SupportabilityUtilizationAzureError;
public static string GetSupportabilityGcpUsabilityError() => SupportabilityUtilizationGcpError;
public static string GetSupportabilityPcfUsabilityError() => SupportabilityUtilizationPcfError;
public static string GetSupportabilityPayloadsDroppedDueToMaxPayloadLimit(string endpoint)
{
return SupportabilityPayloadsDroppedDueToMaxPayloadLimitPrefix + PathSeparator + endpoint;
}
// Agent health events
public static string GetSupportabilityAgentHealthEvent(AgentHealthEvent agentHealthEvent,
string additionalData = null)
{
var metricName = SupportabilityPs + agentHealthEvent;
return (additionalData == null) ? metricName : metricName + PathSeparator + additionalData;
}
// Agent features
private const string SupportabilityFeatureEnabledPs = SupportabilityPs + "FeatureEnabled" + PathSeparator;
public static string GetSupportabilityFeatureEnabled(string featureName)
{
return SupportabilityFeatureEnabledPs + featureName;
}
// Agent API
private const string SupportabilityAgentApiPs = SupportabilityPs + "ApiInvocation" + PathSeparator;
public static string GetSupportabilityAgentApi(string methodName)
{
return SupportabilityAgentApiPs + methodName;
}
// CAT
private const string SupportabilityCAT = SupportabilityPs + "CrossApplicationTracing" + PathSeparator;
private const string SupportabilityCATRequest = SupportabilityCAT + "Request" + PathSeparator;
private const string SupportabilityCATRequestCreate = SupportabilityCATRequest + "Create" + PathSeparator;
private const string SupportabilityCATRequestAccept = SupportabilityCATRequest + "Accept" + PathSeparator;
private const string SupportabilityCATResponse = SupportabilityCAT + "Response" + PathSeparator;
private const string SupportabilityCATResponseCreate = SupportabilityCATResponse + "Create" + PathSeparator;
private const string SupportabilityCATResponseAccept = SupportabilityCATResponse + "Accept" + PathSeparator;
private static readonly Dictionary<CATSupportabilityCondition, string> _catMetricNames = new Dictionary<CATSupportabilityCondition, string>()
{
{ CATSupportabilityCondition.Request_Create_Success, SupportabilityCATRequestCreate + "Success" },
{ CATSupportabilityCondition.Request_Create_Failure, SupportabilityCATRequestCreate + "Exception" },
{ CATSupportabilityCondition.Request_Create_Failure_XProcID, SupportabilityCATRequestCreate + "Exception/CrossProcessID" },
{ CATSupportabilityCondition.Request_Accept_Success, SupportabilityCATRequestAccept + "Success" },
{ CATSupportabilityCondition.Request_Accept_Failure, SupportabilityCATRequestAccept + "Exception" },
{ CATSupportabilityCondition.Request_Accept_Failure_NotTrusted, SupportabilityCATRequestAccept + "Ignored/NotTrusted" },
{ CATSupportabilityCondition.Request_Accept_Failure_Decode, SupportabilityCATRequestAccept + "Ignored/UnableToDecode" },
{ CATSupportabilityCondition.Request_Accept_Multiple, SupportabilityCATRequestAccept + "Warning" + PathSeparator + "MultipleAttempts" },
{ CATSupportabilityCondition.Response_Create_Success, SupportabilityCATResponseCreate + "Success" },
{ CATSupportabilityCondition.Response_Create_Failure, SupportabilityCATResponseCreate + "Exception" },
{ CATSupportabilityCondition.Response_Create_Failure_XProcID, SupportabilityCATResponseCreate + "Exception/CrossProcessID" },
{ CATSupportabilityCondition.Response_Accept_Success, SupportabilityCATResponseAccept + "Success" },
{ CATSupportabilityCondition.Response_Accept_Failure, SupportabilityCATResponseAccept + "Exception" },
{ CATSupportabilityCondition.Response_Accept_MultipleResponses, SupportabilityCATResponseAccept + "Ignored" + PathSeparator + "MultipleAttempts" }
};
///DistributedTracing
private const string SupportabilityDistributedTracePs = SupportabilityPs + "DistributedTrace" + PathSeparator;
private const string SupportabilityDistributedTraceAcceptPayloadPs =
SupportabilityDistributedTracePs + "AcceptPayload" + PathSeparator;
private const string SupportabilityDistributedTraceCreatePayloadPs =
SupportabilityDistributedTracePs + "CreatePayload" + PathSeparator;
private const string SupportabilityDistributedTraceAcceptPayloadIgnoredPs =
SupportabilityDistributedTraceAcceptPayloadPs + "Ignored" + PathSeparator;
/// <summary>Created when AcceptPayload was called successfully</summary>
public const string SupportabilityDistributedTraceAcceptPayloadSuccess =
SupportabilityDistributedTraceAcceptPayloadPs + "Success";
/// <summary>Created when AcceptPayload had a generic exception</summary>
public const string SupportabilityDistributedTraceAcceptPayloadException =
SupportabilityDistributedTraceAcceptPayloadPs + "Exception";
/// <summary>Created when AcceptPayload had a parsing exception</summary>
public const string SupportabilityDistributedTraceAcceptPayloadParseException =
SupportabilityDistributedTraceAcceptPayloadPs + "ParseException";
/// <summary>Created when AcceptPayload was ignored because CreatePayload had already been called</summary>
public const string SupportabilityDistributedTraceAcceptPayloadIgnoredCreateBeforeAccept =
SupportabilityDistributedTraceAcceptPayloadIgnoredPs + "CreateBeforeAccept";
/// <summary>Created when AcceptPayload was ignored because AcceptPayload had already been called</summary>
public const string SupportabilityDistributedTraceAcceptPayloadIgnoredMultiple =
SupportabilityDistributedTraceAcceptPayloadIgnoredPs + "Multiple";
/// <summary>Created when AcceptPayload was ignored because the payload's major version was greater than the agent's</summary>
public const string SupportabilityDistributedTraceAcceptPayloadIgnoredMajorVersion =
SupportabilityDistributedTraceAcceptPayloadIgnoredPs + "MajorVersion";
/// <summary>Created when AcceptPayload was ignored because the payload was null</summary>
public const string SupportabilityDistributedTraceAcceptPayloadIgnoredNull =
SupportabilityDistributedTraceAcceptPayloadIgnoredPs + "Null";
/// <summary>Created when AcceptPayload was ignored because the payload was untrusted</summary>
public const string SupportabilityDistributedTraceAcceptPayloadIgnoredUntrustedAccount =
SupportabilityDistributedTraceAcceptPayloadIgnoredPs + "UntrustedAccount";
/// <summary>Created when CreateDistributedTracePayload was called successfully</summary>
public const string SupportabilityDistributedTraceCreatePayloadSuccess =
SupportabilityDistributedTraceCreatePayloadPs + "Success";
/// <summary>Created when CreateDistributedTracePayload had a generic exception</summary>
public const string SupportabilityDistributedTraceCreatePayloadException =
SupportabilityDistributedTraceCreatePayloadPs + "Exception";
///Trace Context
private const string SupportabilityTraceContextPs = SupportabilityPs + "TraceContext" + PathSeparator;
private const string SupportabilityTraceContextAcceptPs =
SupportabilityTraceContextPs + "Accept" + PathSeparator;
private const string SupportabilityTraceContextCreatePs =
SupportabilityTraceContextPs + "Create" + PathSeparator;
private const string SupportabilityTraceContextTraceParentPs =
SupportabilityTraceContextPs + "TraceParent" + PathSeparator;
private const string SupportabilityTraceContextTraceStatePs =
SupportabilityTraceContextPs + "TraceState" + PathSeparator;
public const string SupportabilityTraceContextAcceptSuccess =
SupportabilityTraceContextAcceptPs + "Success";
public const string SupportabilityTraceContextAcceptException =
SupportabilityTraceContextAcceptPs + "Exception";
public const string SupportabilityTraceContextCreateSuccess =
SupportabilityTraceContextCreatePs + "Success";
public const string SupportabilityTraceContextCreateException =
SupportabilityTraceContextCreatePs + "Exception";
public const string SupportabilityTraceContextTraceParentParseException =
SupportabilityTraceContextTraceParentPs + "Parse" + PathSeparator + "Exception";
public const string SupportabilityTraceContextTraceStateParseException =
SupportabilityTraceContextTraceStatePs + "Parse" + PathSeparator + "Exception";
public const string SupportabilityTraceContextTraceStateInvalidNrEntry =
SupportabilityTraceContextTraceStatePs + "InvalidNrEntry";
public const string SupportabilityTraceContextTraceStateNoNrEntry =
SupportabilityTraceContextTraceStatePs + "NoNrEntry";
//Note the following words from https://source.datanerd.us/agents/agent-specs/blob/master/distributed_tracing/Trace-Context-Payload.md
//In addition to these metrics agents are encouraged to add more specific metrics to assist in debugging issues parsing the payload.
//More detailed parse exception metrics SHOULD start with 'Supportability/TraceContext/Parse/Exception'
public static string GetSupportabilityErrorHttpStatusCodeFromCollector(HttpStatusCode statusCode)
{
return Supportability + PathSeparator + "Agent/Collector/HTTPError" + PathSeparator + (int)statusCode;
}
public static string GetSupportabilityEndpointMethodErrorAttempts(string enpointMethod)
{
return Supportability + PathSeparator + "Agent/Collector" + PathSeparator + enpointMethod + PathSeparator + "Attempts";
}
public static string GetSupportabilityEndpointMethodErrorDuration(string enpointMethod)
{
return Supportability + PathSeparator + "Agent/Collector" + PathSeparator + enpointMethod + PathSeparator + "Duration";
}
// Install Type
private const string SupportabilityInstallTypePs = SupportabilityPs + "Dotnet/InstallType" + PathSeparator;
public static string GetSupportabilityInstallType(string installType)
{
return SupportabilityInstallTypePs + installType;
}
// AppDomain caching disabled
public const string SupportabilityAppDomainCachingDisabled = "Supportability/DotNET/AppDomainCaching/Disabled";
#endregion Supportability
#region Distributed Trace Metrics
private const string Unknown = "Unknown";
//DurationByCaller/parent.type/parent.accountId/parent.appId/transport/all
private const string DistributedTraceDurationByCallerPs = "DurationByCaller" + PathSeparator;
//ErrorsByCaller/parent.type/parent.accountId/parent.appId/transport/all
private const string DistributedTraceErrorsByCallerPs = "ErrorsByCaller" + PathSeparator;
//TransportDuration/parent.type/parent.accountId/parent.appId/transport/all
private const string DistributedTraceTransportDurationPs = "TransportDuration" + PathSeparator;
/// <summary>
/// Returns the metric name based on metricTag
/// </summary>
/// <param name="metricTag">e.g. DistributedTraceDurationByCallerPs or DistributedTraceErrorsByCallerPs or DistributedTraceTransportDurationPs</param>
/// <param name="type">The type of the parent</param>
/// <param name="accountId">The account Id of the parent</param>
/// <param name="app">The app value of the parent</param>
/// <param name="transport">e.g. http, grpc</param>
/// <returns>A metric prefix: e.g. DurationByCaller/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/
/// </returns>
private static string GetDistributedTraceMetricPrefix(
string metricTag,
string type,
string accountId,
string app,
string transport)
{
const int ReserveCapacity = 100;
var sb = new StringBuilder(metricTag, ReserveCapacity)
.Append(type ?? Unknown).Append(PathSeparatorChar)
.Append(accountId ?? Unknown).Append(PathSeparatorChar)
.Append(app ?? Unknown).Append(PathSeparatorChar)
.Append(transport ?? Unknown).Append(PathSeparatorChar);
return sb.ToString();
}
/// <summary>
/// Returns the a tuple of two metric names. The first one ends in /all and the second one ends in allWeb
/// or allOther depending on the input value of isWeb.
/// </summary>
/// <param name="type">The type of the parent</param>
/// <param name="accountId">The account Id of the parent</param>
/// <param name="app">The app value of the parent</param>
/// <param name="transport">e.g. http, grpc</param>
/// <param name="isWeb">if true, creates the allWeb metric name. if false, creates the allOther metric name</param>
/// <returns>A tuple of two strings:
/// <para>DurationByCaller/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/all</para>
/// and
/// <para>DurationByCaller/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/{allWeb|allOther}</para>
/// </returns>
public static (MetricName all, MetricName webOrOther) GetDistributedTraceDurationByCaller(
string type,
string accountId,
string app,
string transport,
bool isWeb)
{
var prefix = GetDistributedTraceMetricPrefix(DistributedTraceDurationByCallerPs, type, accountId, app, transport);
return (all: MetricName.Create(prefix + All), webOrOther: MetricName.Create(prefix + (isWeb ? AllWeb : AllOther)));
}
/// <summary>
/// Returns the a tuple of two metric names. The first one ends in /all and the second one ends in allWeb
/// or allOther depending on the input value of isWeb.
/// </summary>
/// <param name="type">The type of the parent</param>
/// <param name="accountId">The account Id of the parent</param>
/// <param name="app">The app value of the parent</param>
/// <param name="transport">e.g. http, grpc</param>
/// <param name="isWeb">if true, creates the allWeb metric name. if false, creates the allOther metric name</param>
/// <returns>A tuple of two strings:
/// <para>ErrorsByCaller/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/all</para>
/// and
/// <para>ErrorsByCaller/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/{allWeb|allOther}</para>
/// </returns>
public static (MetricName all, MetricName webOrOther) GetDistributedTraceErrorsByCaller(
string type,
string accountId,
string app,
string transport,
bool isWeb)
{
var prefix = GetDistributedTraceMetricPrefix(DistributedTraceErrorsByCallerPs, type, accountId, app, transport);
return (all: MetricName.Create(prefix + All), webOrOther: MetricName.Create(prefix + (isWeb ? AllWeb : AllOther)));
}
/// <summary>
/// Returns the a tuple of two metric names. The first one ends in /all and the second one ends in allWeb
/// or allOther depending on the input value of isWeb.
/// </summary>
/// <param name="type">The type of the parent</param>
/// <param name="accountId">The account Id of the parent</param>
/// <param name="app">The app value of the parent</param>
/// <param name="transport">e.g. http, grpc</param>
/// <param name="isWeb">if true, creates the allWeb metric name. if false, creates the allOther metric name</param>
/// <returns>A tuple of two strings:
/// <para>TransportDuration/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/all</para>
/// and
/// <para>TransportDuration/{parent.type}/{parent.accountId}/{parent.appId}/{transport}/{allWeb|allOther}</para>
/// </returns>
public static (MetricName all, MetricName webOrOther) GetDistributedTraceTransportDuration(
string type,
string accountId,
string app,
string transport,
bool isWeb)
{
var prefix = GetDistributedTraceMetricPrefix(DistributedTraceTransportDurationPs, type, accountId, app, transport);
return (all: MetricName.Create(prefix + All), webOrOther: MetricName.Create(prefix + (isWeb ? AllWeb : AllOther)));
}
#endregion Distributed Trace Metrics
#region Span Metrics
private const string SpanEventsPs = "SpanEvent" + PathSeparator;
public const string SupportabilitySpanEventsSent = SpanEventsPs + "TotalEventsSent";
public const string SupportabilitySpanEventsSeen = SpanEventsPs + "TotalEventsSeen";
public const string SupportabilitySpanEventsLimit = SpanEventsPs + "Limit";
#endregion Span Metrics
#region Infinite Tracing Metrics
private const string SupportabilityInfiniteTracing = "InfiniteTracing" + PathSeparator;
private const string SupportabilityInfiniteTracingSpan = SupportabilityInfiniteTracing + "Span" + PathSeparator;
public const string SupportabilityInfiniteTracingSpanResponseError = SupportabilityInfiniteTracingSpan + "Response/Error";
public const string SupportabilityInfiniteTracingSpanAgentQueueDumped = SupportabilityInfiniteTracingSpan + "AgentQueueDumped";
public const string SupportabilityInfiniteTracingSpanSeen = SupportabilityInfiniteTracingSpan + "Seen";
public const string SupportabilityInfiniteTracingSpanSent = SupportabilityInfiniteTracingSpan + "Sent";
public const string SupportabilityInfiniteTracingSpanSentBatchSize = SupportabilityInfiniteTracingSpan + "BatchSize";
public const string SupportabilityInfiniteTracingSpanQueueSize = SupportabilityInfiniteTracingSpan + "QueueSize";
public const string SupportabilityInfiniteTracingSpanReceived = SupportabilityInfiniteTracingSpan + "Received";
public const string SupportabilityInfiniteTracingSpanDropped = SupportabilityInfiniteTracingSpan + "Dropped";
public const string SupportabilityInfiniteTracingSpanGrpcTimeout = SupportabilityInfiniteTracingSpan + "gRPC" + PathSeparator + "Timeout";
public static string SupportabilityInfiniteTracingSpanGrpcError(string error)
{
return SupportabilityInfiniteTracingSpan + "gRPC" + PathSeparator + error;
}
public static string SupportabilityInfiniteTracingCompression(bool compressionEnabled)
{
return SupportabilityInfiniteTracing + "Compression" + PathSeparator + (compressionEnabled? "enabled" : "disabled");
}
#endregion
#region Performance Metrics
private const string _memoryPrefix = "Memory";
public const string MemoryPhysical = _memoryPrefix + PathSeparator + "Physical"; // Legacy name from before the other memory metrics were added
public const string MemoryWorkingSet = _memoryPrefix + PathSeparator + "WorkingSet";
public const string CpuUserUtilization = "CPU/User/Utilization";
public const string CpuUserTime = "CPU/User Time";
public const string DotNetPerfThreadpool = "Threadpool" + PathSeparator;
public const string DotNetPerfThreadpoolThroughput = DotNetPerfThreadpool + "Throughput" + PathSeparator;
public static string GetThreadpoolUsageStatsName(ThreadType type, ThreadStatus status)
{
return DotNetPerfThreadpool + EnumNameCache<ThreadType>.GetName(type) + PathSeparator + EnumNameCache<ThreadStatus>.GetName(status);
}
public static string GetThreadpoolThroughputStatsName(ThreadpoolThroughputStatsType type)
{
return DotNetPerfThreadpoolThroughput + EnumNameCache<ThreadpoolThroughputStatsType>.GetName(type);
}
private static readonly Dictionary<GCSampleType, string> _gcMetricNames = new Dictionary<GCSampleType, string>
{
{ GCSampleType.HandlesCount , "GC/Handles" },
{ GCSampleType.InducedCount , "GC/Induced" },
{ GCSampleType.PercentTimeInGc , "GC/PercentTimeInGC" },
{ GCSampleType.Gen0CollectionCount , "GC/Gen0/Collections" },
{ GCSampleType.Gen0Size , "GC/Gen0/Size" },