cat_gateway/metrics/
endpoint.rs

1//! Metrics related to endpoint analytics.
2
3use std::sync::LazyLock;
4
5use prometheus::{register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec};
6
7/// Labels for the metrics
8const METRIC_LABELS: [&str; 3] = ["endpoint", "method", "status_code"];
9/// Labels for the client metrics
10const CLIENT_METRIC_LABELS: [&str; 2] = ["client", "status_code"];
11
12// Prometheus Metrics maintained by the service
13
14/// HTTP Request duration histogram.
15pub(crate) static HTTP_REQ_DURATION_MS: LazyLock<HistogramVec> = LazyLock::new(|| {
16    register_histogram_vec!(
17        "http_request_duration_ms",
18        "Duration of HTTP requests in milliseconds",
19        &METRIC_LABELS
20    )
21    .unwrap()
22});
23
24/// HTTP Request CPU Time histogram.
25pub(crate) static HTTP_REQ_CPU_TIME_MS: LazyLock<HistogramVec> = LazyLock::new(|| {
26    register_histogram_vec!(
27        "http_request_cpu_time_ms",
28        "CPU Time of HTTP requests in milliseconds",
29        &METRIC_LABELS
30    )
31    .unwrap()
32});
33
34// No Tacho implemented to enable this.
35// static ref HTTP_REQUEST_RATE: GaugeVec = register_gauge_vec!(
36// "http_request_rate",
37// "Rate of HTTP requests per second",
38// &METRIC_LABELS
39// )
40// .unwrap();
41
42/// HTTP Request count histogram.
43pub(crate) static HTTP_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
44    register_int_counter_vec!(
45        "http_request_count",
46        "Number of HTTP requests",
47        &METRIC_LABELS
48    )
49    .unwrap()
50});
51
52/// Client Request Count histogram.
53pub(crate) static CLIENT_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
54    register_int_counter_vec!(
55        "client_request_count",
56        "Number of HTTP requests per client",
57        &CLIENT_METRIC_LABELS
58    )
59    .unwrap()
60});