-
Notifications
You must be signed in to change notification settings - Fork 0
Using Application Insights Data Output
If you want to output data to application insights, you can use NuGet Package OpenDotNetDiagnostics.Counters.Sinks.ApplicationInsights to do so.
For example, this is how it looks like of the memory usage (working set) at the beginning of an application
And this is another instance of querying the last 24 hours for the working set, get the max value every 30 minutes:
Here's how to use it.
-
Enable application insights for your application
-
Follow the documentation for ASP.NET Core application;
- Or if you are running a worker - Application Insights for Worker Service applications (non-HTTP applications).
-
Configure the instrumentation key or connection string, making sure telemetries are show up for your application.
-
-
Add NuGet package for the sink
-
Assuming you have already exposed the endpoint for dotnet-counters, add package by running:
dotnet add package OpenDotNetDiagnostics.Counters.Sinks.ApplicationInsights --version 1.0.0-beta1
-
-
Add the sink in Program.cs:
// Application insights and its sink builder.Services.AddApplicationInsightsTelemetry(); // Use `AddApplicationInsightsTelemetryWorkerService();` instead in worker builder.Services.AddDotNetCounterApplicationInsightsSink();
-
Run the application
It usually takes a couple of minutes for the data to show up.
-
Query the data
For example, run the following query for
working-set
:customEvents | where name == "OpenDotnetDiagnosticsCounter" // All dotnet-counter events are named `OpenDotnetDiagnosticsCounter` | extend Value_ = todouble(customMeasurements.Value) | extend DisplayName_ = tostring(customDimensions.DisplayName) | where DisplayName_ == "Working Set" // Focus on 1 counter at a time | order by timestamp desc | project timestamp, DisplayName_, Value_ // Project fields to prepare for rendering the chart | render timechart // Render a timechart