Interview frequency: …
Short answer
Use Meter and Counter to record business and performance metrics, then export them in the standard Prometheus format for Grafana dashboards.
Explanation
Modern .NET unifies metrics under System.Diagnostics.Metrics, which is compatible with OpenTelemetry. Instead of relying on old Windows-only Performance Counters, Meter provides lightweight, standard Counters, Histograms, and UpDownCounters that work on Linux and Windows and can be exported to distributed monitoring systems through a /metrics endpoint.
Code example
private static readonly Meter MyMeter = new("MyApp.Orders");
private static readonly Counter<int> OrdersPlaced = MyMeter.CreateCounter<int>("orders_total");
public void PlaceOrder() {
OrdersPlaced.Add(1, new KeyValuePair<string, object?>("country", "EG"));
}Common mistakes
- Creating new Meter objects for every request instead of defining one as static or sharing it as a Singleton.