Skip to content

Commit 3d94460

Browse files
committed
feat: add metric for total bytes inbound received
1 parent 9adab49 commit 3d94460

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

portalnet/src/overlay/service.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,10 @@ impl<
19031903
query_trace_events_tx: Option<UnboundedSender<QueryTraceEvent>>,
19041904
) {
19051905
let mut content = content;
1906+
// report the total bytes of content received
1907+
utp_processing
1908+
.metrics
1909+
.report_bytes_inbound(content.len() as u64);
19061910
// Operate under assumption that all content in the store is valid
19071911
let local_value = utp_processing.store.read().get(&content_key);
19081912
if let Ok(Some(val)) = local_value {

trin-metrics/src/overlay.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct OverlayMetrics {
1818
pub message_total: IntCounterVec,
1919
pub utp_outcome_total: IntCounterVec,
2020
pub utp_active_gauge: IntGaugeVec,
21+
/// Total bytes transferred inbound
22+
pub bytes_inbound_total: IntCounterVec,
2123
pub validation_total: IntCounterVec,
2224
}
2325

@@ -47,6 +49,14 @@ impl OverlayMetrics {
4749
&["protocol", "direction"],
4850
registry
4951
)?;
52+
let bytes_inbound_total = register_int_counter_vec_with_registry!(
53+
opts!(
54+
"trin_bytes_inbound_total",
55+
"count all bytes transferred inbound"
56+
),
57+
&["protocol"],
58+
registry
59+
)?;
5060
let validation_total = register_int_counter_vec_with_registry!(
5161
opts!(
5262
"trin_validation_total",
@@ -59,6 +69,7 @@ impl OverlayMetrics {
5969
message_total,
6070
utp_outcome_total,
6171
utp_active_gauge,
72+
bytes_inbound_total,
6273
validation_total,
6374
})
6475
}
@@ -111,6 +122,14 @@ impl OverlayMetricsReporter {
111122
.with_label_values(&labels)
112123
.inc();
113124
}
125+
/// Increase the total bytes inbound metric by the given length.
126+
pub fn report_bytes_inbound(&self, bytes_len: u64) {
127+
let labels: [&str; 1] = [&self.protocol];
128+
self.overlay_metrics
129+
.bytes_inbound_total
130+
.with_label_values(&labels)
131+
.inc_by(bytes_len)
132+
}
114133

115134
//
116135
// uTP metrics

0 commit comments

Comments
 (0)