Net.Observability.Metrics.Windows
1.2.2
See the version list below for details.
dotnet add package Net.Observability.Metrics.Windows --version 1.2.2
NuGet\Install-Package Net.Observability.Metrics.Windows -Version 1.2.2
<PackageReference Include="Net.Observability.Metrics.Windows" Version="1.2.2" />
paket add Net.Observability.Metrics.Windows --version 1.2.2
#r "nuget: Net.Observability.Metrics.Windows, 1.2.2"
// Install Net.Observability.Metrics.Windows as a Cake Addin
#addin nuget:?package=Net.Observability.Metrics.Windows&version=1.2.2
// Install Net.Observability.Metrics.Windows as a Cake Tool
#tool nuget:?package=Net.Observability.Metrics.Windows&version=1.2.2
Abstract
This nuget provides you with all the logic for custom Windows counters registration to be hosted on a dedicated console app. The produced artifact need to be packed on target service project that is using the counters.
Whenever you install this nuget, you get:
- the logic for counters registration you need to extend (see more about the needed customizations below)
- a Program.cs already with the launch of counter registration
- Note: it's not added to you project but will be compiled on build
- Important: if you receive error MSB4018 during package installation on phase ProduceContentAssets, this is caused by a too long project path. Try move up the solution on the file system hierarchy and then retry installation.
How to set/reset counter value from calling target service code
...
//global IPerformanceCounter counter type
PerformanceCounters.ProcessingTasksCurrentTotal.Increment();
//resetting value (for instance at initialization)
PerformanceCounters.ProcessingTasksCurrentTotal.RawValue = 0;
//instance based IPerformanceCounter counter type
PerformanceCounters.GetCounterFor(PerformanceCounters.ProcessingTasksCurrentTotal, instanceName).Increment();
//resetting value (for instance at initialization)
PerformanceCounters.GetCounterFor(PerformanceCounters.ProcessingTasksCurrentTotal, instanceName).RawValue = 0;
...
...
//global AverageCounter counter type
PerformanceCounters.OutboundMessageProcessingTimeTotal.RegisterExact(stopwatchInstance.ElapsedMilliseconds);
//resetting value (for instance at initialization)
PerformanceCounters.OutboundMessageProcessingTimeTotal.Reset();
//instance based AverageCounter counter type
PerformanceCounters.GetCounterFor(PerformanceCounters.OutboundMessageProcessingTimeTotal, statefulQueueName).RegisterExact(stopwatchInstance.ElapsedMilliseconds);
//resetting value (for instance at initialization)
PerformanceCounters.GetCounterFor(PerformanceCounters.OutboundMessageProcessingTimeTotal, statefulQueueName).Reset();
...
Customizations required
1st needed customization
Following you see the code to add to your console app, for configuring counters to create and then made available for target calling service.
Substitute $rootnamespace$
placeholder with console app name (generally equals to default namespace).
using System.Diagnostics;
using Net.Observability.Metrics.Windows.Instrumentation;
namespace $rootnamespace$.Instrumentation
{
public static partial class PerformanceCounters
{
public static readonly string CategoryName = "YOUR_SPECIFIC_COUNTER_CATEGORY";//this must not be shared between different hosting projects
public static readonly string CategoryHelp = "YOUR_SPECIFIC_COUNTER_CATEGORY_HELP";
#region CONFIGURE REGIONS - LOOK AT INNNER REGIONS
#region CONFIGURE - Custom Counter Name Definition
const string ProcessingTasksCurrentCounterName = "Processing Tasks Current";
const string OutboundMessageProcessingTimeCounterName = "Outbound Message Processing Time, msec";
const string OutboundMessageProcessingTimeBaseCounterName = "Outbound Message Processing Time Base";
#endregion
#region CONFIGURE - Custom Counter To Use Externally
public static readonly IPerformanceCounter ProcessingTasksCurrentTotal = ManagerInstance.GetCounter(CategoryName, ProcessingTasksCurrentCounterName);
public static readonly AveragePerformanceCounter OutboundMessageProcessingTimeTotal = new AveragePerformanceCounter(
ManagerInstance.GetCounter(CategoryName, OutboundMessageProcessingTimeCounterName),
ManagerInstance.GetCounter(CategoryName, OutboundMessageProcessingTimeBaseCounterName));
#endregion
#region CONFIGURE - Custom Counter Creation Information
private static CounterCreationData[] CreateCounterCreationDataArray()
{
return new[]
{
new CounterCreationData(ProcessingTasksCurrentCounterName, "", PerformanceCounterType.NumberOfItems64),
new CounterCreationData(OutboundMessageProcessingTimeCounterName, "", PerformanceCounterType.AverageCount64),
new CounterCreationData(OutboundMessageProcessingTimeBaseCounterName, "", PerformanceCounterType.AverageBase),
};
}
#endregion
#endregion
}
}
2nd needed customization (based on scenario)
Following you see the code to add to a basic batch file to be invoked with administrative privileges (counter registration requirement) by the consuming target calling service.
Note The counter registration batch must be called before the target service goes ready and/or start using custom counters.
For instance for Service Fabric applications this can be accomplished by using startup tasks.
Alternatively, for a standard application or service, we could fork a new System.Diagnostics.Process to launch it and wait for script execution or ensure to be manually invoked by an administrator whenever the counters need to be registered from scratch or new ones are added
Substitute $rootnamespace$
placeholder with console app name (generally equal to default namespace).
REM this to avoid BOM issue
echo %cd%
dotnet $rootnamespace$.dll
REM Evaluate to check error level
:Finish
REM Exit
Exit /B 0
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- DotNetty.Common (>= 0.7.2)
- System.Buffers (>= 4.5.1)
- System.Diagnostics.PerformanceCounter (>= 6.0.1)
- System.Memory (>= 4.5.5)
- System.Numerics.Vectors (>= 4.5.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- DotNetty.Common (>= 0.7.2)
- System.Buffers (>= 4.5.1)
- System.Diagnostics.PerformanceCounter (>= 6.0.1)
- System.Memory (>= 4.5.5)
- System.Numerics.Vectors (>= 4.5.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.ValueTuple (>= 4.5.0)
-
net6.0
- DotNetty.Common (>= 0.7.2)
- System.Buffers (>= 4.5.1)
- System.Diagnostics.PerformanceCounter (>= 6.0.1)
- System.Memory (>= 4.5.5)
- System.Numerics.Vectors (>= 4.5.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.ValueTuple (>= 4.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.