use prometric::{Counter, Gauge, Histogram, Summary};
use prometric_derive::metrics;
#[metrics(scope = "app")]
struct AppMetrics {
#[metric(rename = "http_requests_total", labels = ["method", "path"])]
http_requests: Counter,
#[metric(labels = ["method", "path"], buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0])]
http_requests_duration: Histogram,
#[metric(labels = ["method", "path"], quantiles = [0.0, 0.5, 0.9, 0.95, 0.99, 0.999, 1.0])]
http_request_sizes: Summary,
#[metric(rename = "current_active_users", labels = ["service"], help = "The current number of active users.")]
current_users: Gauge,
#[metric(rename = "account_balance", labels = ["account_id"])]
account_balance: Gauge<f64>,
#[metric]
errors: Counter,
}
#[tokio::main(flavor = "current_thread")]
async fn main() {
let metrics =
AppMetrics::builder().with_label("host", "localhost").with_label("port", "8080").build();
metrics.http_requests("GET", "/").inc();
metrics.http_requests_duration("GET", "/").observe(1.0);
metrics.http_request_sizes("GET", "/").observe(12345);
metrics.current_users("service-1").set(10);
metrics.account_balance("1234567890").set(-12.2);
metrics.errors().inc();
}