TaskHub.Shared

Metrics Guide

TaskHub.Shared uses prometheus-net to collect and expose metrics. The system provides a unified IMetricsService for recording custom application metrics.

Key Metrics Types

Counter

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"));

Gauge

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);

Histogram

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

Exposing Metrics

Metrics are automatically exposed via the /metrics endpoint. This endpoint is secured and intended to be scraped by a Prometheus server.

Configuration

Define your metrics endpoints and service-level tags in appsettings.json.

"Metrics": {
  "Port": 9090,
  "IsDefaultLabelsEnabled": true
}

Built-in Metrics

TaskHub.Shared automatically collects:

Visualizing with Grafana

Once Prometheus is scraping your /metrics endpoint, you can use pre-defined Grafana dashboards to visualize: