cat_gateway/metrics/
endpoint.rs1use std::sync::LazyLock;
4
5use prometheus::{
6 register_histogram_vec, register_int_counter, register_int_counter_vec, HistogramVec,
7 IntCounter, IntCounterVec,
8};
9
10const METRIC_LABELS: [&str; 3] = ["endpoint", "method", "status_code"];
12const CLIENT_METRIC_LABELS: [&str; 2] = ["client", "status_code"];
14
15pub(crate) static HTTP_REQ_DURATION_MS: LazyLock<HistogramVec> = LazyLock::new(|| {
19 register_histogram_vec!(
20 "http_request_duration_ms",
21 "Duration of HTTP requests in milliseconds",
22 &METRIC_LABELS
23 )
24 .unwrap()
25});
26
27pub(crate) static HTTP_REQ_CPU_TIME_MS: LazyLock<HistogramVec> = LazyLock::new(|| {
29 register_histogram_vec!(
30 "http_request_cpu_time_ms",
31 "CPU Time of HTTP requests in milliseconds",
32 &METRIC_LABELS
33 )
34 .unwrap()
35});
36
37pub(crate) static HTTP_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
47 register_int_counter_vec!(
48 "http_request_count",
49 "Number of HTTP requests",
50 &METRIC_LABELS
51 )
52 .unwrap()
53});
54
55pub(crate) static CLIENT_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
57 register_int_counter_vec!(
58 "client_request_count",
59 "Number of HTTP requests per client",
60 &CLIENT_METRIC_LABELS
61 )
62 .unwrap()
63});
64
65pub(crate) static NOT_FOUND_COUNT: LazyLock<IntCounter> = LazyLock::new(|| {
68 register_int_counter!("response_404", "Number of 404 not found response",).unwrap()
69});