snap_tun/metrics.rs
1// Copyright 2025 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! SNAP tunnel metrics.
15
16use prometheus::IntCounter;
17use scion_sdk_observability::metrics::registry::MetricsRegistry;
18
19/// SNAP tunnel metrics.
20pub struct Metrics {
21 /// Sender metrics.
22 pub sender_metrics: SenderMetrics,
23 /// Receiver metrics.
24 pub receiver_metrics: ReceiverMetrics,
25}
26
27impl Metrics {
28 /// Create new metrics instance with the given registry.
29 pub fn new(metrics_registry: &MetricsRegistry) -> Self {
30 Metrics {
31 sender_metrics: SenderMetrics::new(metrics_registry),
32 receiver_metrics: ReceiverMetrics::new(metrics_registry),
33 }
34 }
35}
36
37/// SNAP tunnel sender metrics.
38#[derive(Debug, Clone)]
39pub struct SenderMetrics {
40 /// Total number of datagrams sent by the sender.
41 pub datagrams_sent_total: IntCounter,
42}
43
44impl SenderMetrics {
45 /// Create new sender metrics instance with the given registry.
46 pub fn new(metrics_registry: &MetricsRegistry) -> Self {
47 SenderMetrics {
48 datagrams_sent_total: metrics_registry.int_counter(
49 "snaptun_datagrams_sent_total",
50 "Total number of datagrams sent by the sender.",
51 ),
52 }
53 }
54}
55
56/// SNAP tunnel receiver metrics.
57#[derive(Debug, Clone)]
58pub struct ReceiverMetrics {
59 /// Total number of datagrams received by the receiver.
60 pub datagrams_received_total: IntCounter,
61}
62
63impl ReceiverMetrics {
64 /// New receiver metrics instance with the given registry.
65 pub fn new(metrics_registry: &MetricsRegistry) -> Self {
66 ReceiverMetrics {
67 datagrams_received_total: metrics_registry.int_counter(
68 "snaptun_datagrams_received_total",
69 "Total number of datagrams received by the receiver.",
70 ),
71 }
72 }
73}