use prometheus::{IntCounter, IntGauge};
use scion_sdk_observability::metrics::registry::MetricsRegistry;
#[derive(Debug, Clone)]
pub struct TunnelGatewayMetrics {
pub snaptun_connections_active: IntGauge,
}
impl TunnelGatewayMetrics {
pub fn new(metrics_registry: &MetricsRegistry) -> Self {
TunnelGatewayMetrics {
snaptun_connections_active: metrics_registry.int_gauge(
"snap_snaptun_active_connections",
"Total number of active snaptun connections.",
),
}
}
}
#[derive(Debug, Clone)]
pub struct TunnelGatewayDispatcherMetrics {
pub dispatch_queue_size: IntGauge,
pub full_dispatch_queue_errors: IntCounter,
pub closed_dispatch_queue_errors: IntCounter,
pub invalid_packets_errors: IntCounter,
pub connection_closed_errors: IntCounter,
pub new_assigned_address_errors: IntCounter,
pub no_address_assigned_errors: IntCounter,
pub send_datagram_errors: IntCounter,
pub missing_tunnel_errors: IntCounter,
}
impl TunnelGatewayDispatcherMetrics {
pub fn new(metrics_registry: &MetricsRegistry) -> Self {
let dispatch_errors = metrics_registry.int_counter_vec(
"snap_tunnel_gw_dispatch_errors_total",
"Total number of errors when dispatching a packet to the tunnel gateway.",
&["error_type"],
);
let forwarding_errors = metrics_registry.int_counter_vec(
"snap_tunnel_gw_forwarding_errors_total",
"Total number of errors when forwarding a packet to corresponding snaptun.",
&["error_type"],
);
TunnelGatewayDispatcherMetrics {
dispatch_queue_size: metrics_registry.int_gauge(
"snap_tunnel_gw_dispatch_queue_size",
"Current size of the tunnel gateway dispatch queue.",
),
full_dispatch_queue_errors: dispatch_errors.with_label_values(&["queue_full"]),
closed_dispatch_queue_errors: dispatch_errors.with_label_values(&["queue_closed"]),
invalid_packets_errors: forwarding_errors.with_label_values(&["invalid_packet"]),
connection_closed_errors: forwarding_errors.with_label_values(&["connection_closed"]),
new_assigned_address_errors: forwarding_errors
.with_label_values(&["new_assigned_address"]),
no_address_assigned_errors: forwarding_errors
.with_label_values(&["no_address_assigned"]),
send_datagram_errors: forwarding_errors.with_label_values(&["send_datagram_error"]),
missing_tunnel_errors: forwarding_errors.with_label_values(&["tunnel_missing"]),
}
}
}