Skip to content

Commit fe27aa9

Browse files
authored
Add quilkin_allocated_xdp_packets metric (#1357)
This tracks the number of packets that are currently "allocated" from the Umem, either waiting to be filled with received data, or waiting to be sent This tracks a single metric, as I don't think we can track it on a per queue basis due to cardinality, but I might be wrong about that Resolves: #1168
1 parent 5f3e489 commit fe27aa9

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/metrics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,21 @@ pub(crate) fn provider_task_failures_total(provider_task: &str) -> IntCounter {
640640
PROVIDER_TASK_FAILURES_TOTAL.with_label_values(&[provider_task])
641641
}
642642

643+
pub(crate) fn allocated_xdp_packets() -> &'static IntGauge {
644+
static ALLOCATED: Lazy<IntGauge> = Lazy::new(|| {
645+
prometheus::register_int_gauge_with_registry! {
646+
prometheus::opts! {
647+
"quilkin_allocated_xdp_packets",
648+
"The number of packets that are allocated from a UMEM",
649+
},
650+
registry(),
651+
}
652+
.unwrap()
653+
});
654+
655+
&ALLOCATED
656+
}
657+
643658
/// Create a generic metrics options.
644659
/// Use `filter_opts` instead if the intended target is a filter.
645660
pub fn opts(name: &str, subsystem: &str, description: &str) -> Opts {

src/net/io/nic/xdp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ fn io_loop(
429429
let mut rx_slab = xdp::slab::StackSlab::<BATCH_SIZE>::new();
430430
let mut tx_slab = xdp::slab::StackSlab::<{ BATCH_SIZE << 2 }>::new();
431431
let mut pending_sends = 0;
432+
let mut outstanding = umem.outstanding() as i64;
433+
434+
crate::metrics::allocated_xdp_packets().add(outstanding);
432435

433436
// SAFETY: the cases of unsafe in this code block all concern the relationship
434437
// between frames and the Umem, the frames cannot outlive the Umem which is
@@ -492,6 +495,10 @@ fn io_loop(
492495
// Return frames that have completed sending
493496
pending_sends += enqueued_sends;
494497
pending_sends -= completion.dequeue(&mut umem, pending_sends);
498+
499+
let new = umem.outstanding() as i64;
500+
crate::metrics::allocated_xdp_packets().add(new - outstanding);
501+
outstanding = new;
495502
}
496503
}
497504
}

0 commit comments

Comments
 (0)