TaskHub.Shared uses prometheus-net to collect and expose metrics. The system provides a unified IMetricsService for recording custom application metrics.
A value that only increases (e.g., number of requests, total errors).
var counter = metrics.CreateCounter("orders_total", "Total number of orders processed", "status");
counter.Inc(("status", "completed"));
A value that can go up and down (e.g., active connections, queue depth).
var gauge = metrics.CreateGauge("active_users", "Current number of active users");
gauge.Set(42);
A value sampled into buckets, used for distribution (e.g., request latency).
using var timer = metrics.Measure("db_query_duration", "Duration of DB queries", "query_type");
// ... db call
timer.Dispose(); // Records the duration
Metrics are automatically exposed via the /metrics endpoint. This endpoint is secured and intended to be scraped by a Prometheus server.
Define your metrics endpoints and service-level tags in appsettings.json.
"Metrics": {
"Port": 9090,
"IsDefaultLabelsEnabled": true
}
TaskHub.Shared automatically collects:
CommandsBus.Once Prometheus is scraping your /metrics endpoint, you can use pre-defined Grafana dashboards to visualize: