cat_gateway/metrics/
endpoint.rs

1//! Metrics related to endpoint analytics.
2
3use std::sync::LazyLock;
4
5use prometheus::{
6    register_histogram_vec, register_int_counter, register_int_counter_vec, HistogramVec,
7    IntCounter, IntCounterVec,
8};
9
10/// Labels for the metrics
11const METRIC_LABELS: [&str; 3] = ["endpoint", "method", "status_code"];
12/// Labels for the client metrics
13const CLIENT_METRIC_LABELS: [&str; 2] = ["client", "status_code"];
14
15// Prometheus Metrics maintained by the service
16
17/// HTTP Request duration histogram.
18pub(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
27/// HTTP Request CPU Time histogram.
28pub(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
37// No Tacho implemented to enable this.
38// static ref HTTP_REQUEST_RATE: GaugeVec = register_gauge_vec!(
39// "http_request_rate",
40// "Rate of HTTP requests per second",
41// &METRIC_LABELS
42// )
43// .unwrap();
44
45/// HTTP Request count histogram.
46pub(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
55/// Client Request Count histogram.
56pub(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
65/// Metric counter to track the number of HTTP 404 Not Found responses.
66/// It is use for monitoring crawler activity or requests to invalid URLs.
67pub(crate) static NOT_FOUND_COUNT: LazyLock<IntCounter> = LazyLock::new(|| {
68    register_int_counter!("response_404", "Number of 404 not found response",).unwrap()
69});