Skip to content

Commit ec9a80c

Browse files
committed
feat: add metric for total bytes inbound received
1 parent 0714514 commit ec9a80c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

crates/metrics/src/overlay.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct OverlayMetrics {
2323
pub utp_outcome_total: IntCounterVec,
2424
pub utp_active_gauge: IntGaugeVec,
2525
pub utp_connection_duration: HistogramVec,
26+
/// Total bytes transferred inbound
27+
pub bytes_inbound_total: IntCounterVec,
2628
pub validation_total: IntCounterVec,
2729
}
2830

@@ -60,6 +62,14 @@ impl OverlayMetrics {
6062
&["protocol", "direction"],
6163
registry
6264
)?;
65+
let bytes_inbound_total = register_int_counter_vec_with_registry!(
66+
opts!(
67+
"trin_bytes_inbound_total",
68+
"count all bytes transferred inbound"
69+
),
70+
&["protocol"],
71+
registry
72+
)?;
6373
let validation_total = register_int_counter_vec_with_registry!(
6474
opts!(
6575
"trin_validation_total",
@@ -73,6 +83,7 @@ impl OverlayMetrics {
7383
utp_outcome_total,
7484
utp_active_gauge,
7585
utp_connection_duration,
86+
bytes_inbound_total,
7687
validation_total,
7788
})
7889
}
@@ -125,6 +136,14 @@ impl OverlayMetricsReporter {
125136
.with_label_values(&labels)
126137
.inc();
127138
}
139+
/// Increase the total bytes inbound metric by the given length.
140+
pub fn report_bytes_inbound(&self, bytes_len: u64) {
141+
let labels: [&str; 1] = [&self.protocol];
142+
self.overlay_metrics
143+
.bytes_inbound_total
144+
.with_label_values(&labels)
145+
.inc_by(bytes_len)
146+
}
128147

129148
//
130149
// uTP metrics

crates/portalnet/src/overlay/service/manager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,10 @@ impl<
17541754
query_trace_events_tx: Option<UnboundedSender<QueryTraceEvent>>,
17551755
) {
17561756
let mut content = content;
1757+
// report the total bytes of content received
1758+
utp_processing
1759+
.metrics
1760+
.report_bytes_inbound(content.len() as u64);
17571761
// Operate under assumption that all content in the store is valid
17581762
let local_value = utp_processing.store.read().get(&content_key);
17591763
if let Ok(Some(val)) = local_value {

0 commit comments

Comments
 (0)