Skip to content

Commit c4012cd

Browse files
[AzureMonitorExporter] Add Performance Counter Support (#52705)
* Added Performance metrics. * Update tests * copilot feedback * request and exception rate fix * Fix event id numbers * remove runtime metrics * test update * test fix * Revert test change as rate is unpreditable due to CI calculated exceptions.
1 parent 752049e commit c4012cd

File tree

4 files changed

+457
-38
lines changed

4 files changed

+457
-38
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,5 +491,50 @@ public void CustomerSdkStatsInitializationFailed(Exception ex)
491491

492492
[Event(50, Message = "Invalid sampler argument '{1}' for sampler '{0}'. Ignoring.", Level = EventLevel.Warning)]
493493
public void InvalidSamplerArgument(string samplerType, string samplerArg) => WriteEvent(50, samplerType, samplerArg);
494+
495+
[Event(51, Message = "Failure to calculate CPU Counter. Unexpected negative timespan: PreviousCollectedTime: {0}. RecentCollectedTime: {1}. Not user actionable.", Level = EventLevel.Error)]
496+
public void ProcessCountersUnexpectedNegativeTimeSpan(long previousCollectedTime, long recentCollectedTime) => WriteEvent(51, previousCollectedTime, recentCollectedTime);
497+
498+
[Event(52, Message = "Failure to calculate CPU Counter. Unexpected negative value: PreviousCollectedValue: {0}. RecentCollectedValue: {1}. Not user actionable.", Level = EventLevel.Error)]
499+
public void ProcessCountersUnexpectedNegativeValue(long previousCollectedValue, long recentCollectedValue) => WriteEvent(52, previousCollectedValue, recentCollectedValue);
500+
501+
[Event(53, Message = "Calculated Cpu Counter: Period: {0}. DiffValue: {1}. CalculatedValue: {2}. ProcessorCount: {3}. NormalizedValue: {4}", Level = EventLevel.Verbose)]
502+
public void ProcessCountersCpuCounter(long period, long diffValue, double calculatedValue, int processorCount, double normalizedValue) => WriteEvent(53, period, diffValue, calculatedValue, processorCount, normalizedValue);
503+
504+
[NonEvent]
505+
public void FailedToCollectProcessPrivateBytes(System.Exception ex)
506+
{
507+
if (IsEnabled(EventLevel.Error))
508+
{
509+
FailedToCollectProcessPrivateBytes(ex.FlattenException().ToInvariantString());
510+
}
511+
}
512+
513+
[Event(54, Message = "Failed to collect Process Private Bytes due to an exception. {0}", Level = EventLevel.Warning)]
514+
public void FailedToCollectProcessPrivateBytes(string exceptionMessage) => WriteEvent(54, exceptionMessage);
515+
516+
[NonEvent]
517+
public void FailedToCalculateRequestRate(Exception ex)
518+
{
519+
if (IsEnabled(EventLevel.Warning))
520+
{
521+
FailedToCalculateRequestRate(ex.FlattenException().ToInvariantString());
522+
}
523+
}
524+
525+
[Event(55, Message = "Failed to calculate request rate due to an exception. {0}", Level = EventLevel.Warning)]
526+
public void FailedToCalculateRequestRate(string exceptionMessage) => WriteEvent(55, exceptionMessage);
527+
528+
[NonEvent]
529+
public void FailedToCalculateExceptionRate(Exception ex)
530+
{
531+
if (IsEnabled(EventLevel.Warning))
532+
{
533+
FailedToCalculateExceptionRate(ex.FlattenException().ToInvariantString());
534+
}
535+
}
536+
537+
[Event(56, Message = "Failed to calculate exception rate due to an exception. {0}", Level = EventLevel.Warning)]
538+
public void FailedToCalculateExceptionRate(string exceptionMessage) => WriteEvent(56, exceptionMessage);
494539
}
495540
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace Azure.Monitor.OpenTelemetry.Exporter.Internals
5+
{
6+
internal static class PerfCounterConstants
7+
{
8+
internal const string PerfCounterMeterName = "PerfCounterMeter";
9+
internal const string RequestRateInstrumentationName = "RequestCounterRate";
10+
internal const string ProcessCpuInstrumentationName = "ProcessCpu";
11+
internal const string ProcessCpuNormalizedInstrumentationName = "ProcessCpuNormalized";
12+
internal const string ProcessPrivateBytesInstrumentationName = "ProcessPrivateBytes";
13+
internal const string ExceptionRateName = "AzureMonitorExceptionRate";
14+
15+
// Breeze perf counter names
16+
internal const string ExceptionRateMetricIdValue = "\\.NET CLR Exceptions(??APP_CLR_PROC??)\\# of Exceps Thrown / sec";
17+
internal const string RequestRateMetricIdValue = "\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec";
18+
internal const string ProcessCpuMetricIdValue = "\\Process(??APP_WIN32_PROC??)\\% Processor Time";
19+
internal const string ProcessCpuNormalizedMetricIdValue = "\\Process(??APP_WIN32_PROC??)\\% Processor Time Normalized";
20+
internal const string ProcessPrivateBytesMetricIdValue = "\\Process(??APP_WIN32_PROC??)\\Private Bytes";
21+
}
22+
}

0 commit comments

Comments
 (0)