Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/64j0/dotnet-builtin-metrics

This repository holds a very simple HTTP API that uses ASP.NET and Giraffe to exemplify the usage of .NET 8 built-in metrics feature
https://github.com/64j0/dotnet-builtin-metrics

Last synced: 2 days ago
JSON representation

This repository holds a very simple HTTP API that uses ASP.NET and Giraffe to exemplify the usage of .NET 8 built-in metrics feature

Awesome Lists containing this project

README

        

#+TITLE: .NET Built-in Performance
#+AUTHOR: 64J0

The idea to create this project was born after watching this video from Nick
Chapsas named [[https://www.youtube.com/watch?v=8kDugxr3Hdg&ab_channel=NickChapsas][Measure Your Application's Performance in .NET]]. This repository
holds a very simple HTTP API that uses ASP.NET and Giraffe to exemplify what are
the collected metrics by with built-in .NET feature.

+ ASP.NET Core built-in metrics documentation: [[https://learn.microsoft.com/en-us/dotnet/core/diagnostics/built-in-metrics-aspnetcore?view=aspnetcore-8.0][link]].
+ Instrumentation documentation: [[https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-instrumentation?view=aspnetcore-8.0][link]].
+ View metrics in Grafana with OpenTelemetry and Prometheus: [[https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-collection?view=aspnetcore-8.0#view-metrics-in-grafana-with-opentelemetry-and-prometheus][link]].

** Visualize the metrics

One option is to use the [[https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters][dotnet-counters]] tool.

#+BEGIN_SRC bash :tangle no
# restore our dotnet tools
dotnet tool restore

# start the server
dotnet run
# use curl to call the /ping endpoint
# curl localhost:3000/ping
# check Prometheus-style metrics on /metrics endpoint

# in another terminal
# list the process id of the dotnet processes
dotnet dotnet-counters ps

# start monitoring the server process id
dotnet dotnet-counters monitor --process-id --counters System.Runtime,MyApi.Ping
#+END_SRC

Example metrics:

[[./assets/example-metrics.png]]

+ It's probably with some bug since I'm using a pre-release version of the ~OpenTelemetry.Exporter.Prometheus.AspNetCore~ package.