sui_edge_proxy/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use prometheus::{
5    register_gauge_vec_with_registry, register_histogram_vec_with_registry,
6    register_int_counter_vec_with_registry, GaugeVec, HistogramVec, IntCounterVec, Registry,
7};
8
9#[derive(Clone)]
10pub struct AppMetrics {
11    pub backend_up: GaugeVec,
12    pub requests_total: IntCounterVec,
13    pub request_latency: HistogramVec,
14    pub upstream_response_latency: HistogramVec,
15    pub response_size_bytes: HistogramVec,
16    pub request_size_bytes: HistogramVec,
17    pub timeouts_total: IntCounterVec,
18    pub error_counts: IntCounterVec,
19    pub request_body_read_failures: IntCounterVec,
20    pub upstream_request_failures: IntCounterVec,
21}
22
23impl AppMetrics {
24    pub fn new(registry: &Registry) -> Self {
25        Self {
26            backend_up: register_gauge_vec_with_registry!(
27                "edge_proxy_backend_up",
28                "Indicates if the backend is up (1) or down (0)",
29                &["peer_type"],
30                registry
31            )
32            .unwrap(),
33            requests_total: register_int_counter_vec_with_registry!(
34                "edge_proxy_requests_total",
35                "Total number of requests processed by the edge proxy",
36                &["peer_type", "status"],
37                registry
38            )
39            .unwrap(),
40            request_latency: register_histogram_vec_with_registry!(
41                "edge_proxy_request_latency",
42                "Request latency in seconds",
43                &["peer_type"],
44                registry
45            )
46            .unwrap(),
47            upstream_response_latency: register_histogram_vec_with_registry!(
48                "edge_proxy_upstream_response_latency",
49                "Upstream response latency in seconds",
50                &["peer_type", "status"],
51                registry
52            )
53            .unwrap(),
54            response_size_bytes: register_histogram_vec_with_registry!(
55                "edge_proxy_response_size_bytes",
56                "Size of responses in bytes",
57                &["peer_type"],
58                registry
59            )
60            .unwrap(),
61            request_size_bytes: register_histogram_vec_with_registry!(
62                "edge_proxy_request_size_bytes",
63                "Size of incoming requests in bytes",
64                &["peer_type"],
65                registry
66            )
67            .unwrap(),
68            timeouts_total: register_int_counter_vec_with_registry!(
69                "edge_proxy_timeouts_total",
70                "Total number of timed-out requests",
71                &["peer_type"],
72                registry
73            )
74            .unwrap(),
75            error_counts: register_int_counter_vec_with_registry!(
76                "edge_proxy_error_counts",
77                "Total number of errors encountered by the edge proxy",
78                &["peer_type", "error_type"],
79                registry
80            )
81            .unwrap(),
82            request_body_read_failures: register_int_counter_vec_with_registry!(
83                "edge_proxy_request_body_read_failures",
84                "Total number of request body read failures",
85                &[],
86                registry
87            )
88            .unwrap(),
89            upstream_request_failures: register_int_counter_vec_with_registry!(
90                "edge_proxy_upstream_request_failures",
91                "Total number of upstream request failures",
92                &["peer_type", "error_type"],
93                registry
94            )
95            .unwrap(),
96        }
97    }
98}