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