mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 09:37:55 +00:00
Adjustments to Kademlia-related metrics (#5660)
* Turn kbuckets_num_nodes into a GaugeVec * random_kademlia_queries -> kademlia_random_queries * kademalia_random_queries_total now a CounterVec * Add metrics about records store
This commit is contained in:
@@ -880,7 +880,10 @@ struct Metrics {
|
||||
incoming_connections_total: Counter<U64>,
|
||||
is_major_syncing: Gauge<U64>,
|
||||
issued_light_requests: Counter<U64>,
|
||||
kbuckets_num_nodes: Gauge<U64>,
|
||||
kademlia_random_queries_total: CounterVec<U64>,
|
||||
kademlia_records_count: GaugeVec<U64>,
|
||||
kademlia_records_sizes_total: GaugeVec<U64>,
|
||||
kbuckets_num_nodes: GaugeVec<U64>,
|
||||
listeners_local_addresses: Gauge<U64>,
|
||||
listeners_errors_total: Counter<U64>,
|
||||
network_per_sec_bytes: GaugeVec<U64>,
|
||||
@@ -893,7 +896,6 @@ struct Metrics {
|
||||
peerset_num_requested: Gauge<U64>,
|
||||
pending_connections: Gauge<U64>,
|
||||
pending_connections_errors_total: CounterVec<U64>,
|
||||
random_kademalia_queries_total: Counter<U64>,
|
||||
}
|
||||
|
||||
impl Metrics {
|
||||
@@ -945,8 +947,33 @@ impl Metrics {
|
||||
"issued_light_requests",
|
||||
"Number of light client requests that our node has issued.",
|
||||
)?, registry)?,
|
||||
kbuckets_num_nodes: register(Gauge::new(
|
||||
"sub_libp2p_kbuckets_num_nodes", "Number of nodes in the Kademlia k-buckets"
|
||||
kademlia_random_queries_total: register(CounterVec::new(
|
||||
Opts::new(
|
||||
"sub_libp2p_kademlia_random_queries_total",
|
||||
"Number of random Kademlia queries started"
|
||||
),
|
||||
&["protocol"]
|
||||
)?, registry)?,
|
||||
kademlia_records_count: register(GaugeVec::new(
|
||||
Opts::new(
|
||||
"sub_libp2p_kademlia_records_count",
|
||||
"Number of records in the Kademlia records store"
|
||||
),
|
||||
&["protocol"]
|
||||
)?, registry)?,
|
||||
kademlia_records_sizes_total: register(GaugeVec::new(
|
||||
Opts::new(
|
||||
"sub_libp2p_kademlia_records_sizes_total",
|
||||
"Total size of all the records in the Kademlia records store"
|
||||
),
|
||||
&["protocol"]
|
||||
)?, registry)?,
|
||||
kbuckets_num_nodes: register(GaugeVec::new(
|
||||
Opts::new(
|
||||
"sub_libp2p_kbuckets_num_nodes",
|
||||
"Number of nodes in the Kademlia k-buckets"
|
||||
),
|
||||
&["protocol"]
|
||||
)?, registry)?,
|
||||
listeners_local_addresses: register(Gauge::new(
|
||||
"sub_libp2p_listeners_local_addresses", "Number of local addresses we're listening on"
|
||||
@@ -1017,24 +1044,23 @@ impl Metrics {
|
||||
),
|
||||
&["reason"]
|
||||
)?, registry)?,
|
||||
random_kademalia_queries_total: register(Counter::new(
|
||||
"sub_libp2p_random_kademalia_queries_total", "Number of random Kademlia queries started",
|
||||
)?, registry)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn update_with_network_event(&self, event: &Event) {
|
||||
match event {
|
||||
Event::NotificationStreamOpened { engine_id, .. } => {
|
||||
self.notifications_streams_opened_total.with_label_values(&[&engine_id_to_string(&engine_id)]).inc();
|
||||
self.notifications_streams_opened_total
|
||||
.with_label_values(&[&maybe_utf8_bytes_to_string(engine_id)]).inc();
|
||||
},
|
||||
Event::NotificationStreamClosed { engine_id, .. } => {
|
||||
self.notifications_streams_closed_total.with_label_values(&[&engine_id_to_string(&engine_id)]).inc();
|
||||
self.notifications_streams_closed_total
|
||||
.with_label_values(&[&maybe_utf8_bytes_to_string(engine_id)]).inc();
|
||||
},
|
||||
Event::NotificationsReceived { messages, .. } => {
|
||||
for (engine_id, message) in messages {
|
||||
self.notifications_sizes
|
||||
.with_label_values(&["in", &engine_id_to_string(&engine_id)])
|
||||
.with_label_values(&["in", &maybe_utf8_bytes_to_string(engine_id)])
|
||||
.observe(message.len() as f64);
|
||||
}
|
||||
},
|
||||
@@ -1097,7 +1123,7 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
ServiceToWorkerMsg::WriteNotification { message, engine_id, target } => {
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.notifications_sizes
|
||||
.with_label_values(&["out", &engine_id_to_string(&engine_id)])
|
||||
.with_label_values(&["out", &maybe_utf8_bytes_to_string(&engine_id)])
|
||||
.observe(message.len() as f64);
|
||||
}
|
||||
this.network_service.user_protocol_mut().write_notification(target, engine_id, message)
|
||||
@@ -1137,9 +1163,11 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
}
|
||||
this.import_queue.import_finality_proof(origin, hash, nb, proof);
|
||||
},
|
||||
Poll::Ready(SwarmEvent::Behaviour(BehaviourOut::RandomKademliaStarted)) => {
|
||||
Poll::Ready(SwarmEvent::Behaviour(BehaviourOut::RandomKademliaStarted(protocol))) => {
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.random_kademalia_queries_total.inc();
|
||||
metrics.kademlia_random_queries_total
|
||||
.with_label_values(&[&maybe_utf8_bytes_to_string(protocol.as_bytes())])
|
||||
.inc();
|
||||
}
|
||||
},
|
||||
Poll::Ready(SwarmEvent::Behaviour(BehaviourOut::Event(ev))) => {
|
||||
@@ -1292,7 +1320,18 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
metrics.network_per_sec_bytes.with_label_values(&["in"]).set(this.service.bandwidth.average_download_per_sec());
|
||||
metrics.network_per_sec_bytes.with_label_values(&["out"]).set(this.service.bandwidth.average_upload_per_sec());
|
||||
metrics.is_major_syncing.set(is_major_syncing as u64);
|
||||
metrics.kbuckets_num_nodes.set(this.network_service.num_kbuckets_entries() as u64);
|
||||
for (proto, num_entries) in this.network_service.num_kbuckets_entries() {
|
||||
let proto = maybe_utf8_bytes_to_string(proto.as_bytes());
|
||||
metrics.kbuckets_num_nodes.with_label_values(&[&proto]).set(num_entries as u64);
|
||||
}
|
||||
for (proto, num_entries) in this.network_service.num_kademlia_records() {
|
||||
let proto = maybe_utf8_bytes_to_string(proto.as_bytes());
|
||||
metrics.kademlia_records_count.with_label_values(&[&proto]).set(num_entries as u64);
|
||||
}
|
||||
for (proto, num_entries) in this.network_service.kademlia_records_total_size() {
|
||||
let proto = maybe_utf8_bytes_to_string(proto.as_bytes());
|
||||
metrics.kademlia_records_sizes_total.with_label_values(&[&proto]).set(num_entries as u64);
|
||||
}
|
||||
metrics.peers_count.set(num_connected_peers as u64);
|
||||
metrics.peerset_num_discovered.set(this.network_service.user_protocol().num_discovered_peers() as u64);
|
||||
metrics.peerset_num_requested.set(this.network_service.user_protocol().requested_peers().count() as u64);
|
||||
@@ -1306,8 +1345,10 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
impl<B: BlockT + 'static, H: ExHashT> Unpin for NetworkWorker<B, H> {
|
||||
}
|
||||
|
||||
/// Turns a `ConsensusEngineId` into a representable string.
|
||||
fn engine_id_to_string(id: &ConsensusEngineId) -> Cow<str> {
|
||||
/// Turns bytes that are potentially UTF-8 into a reasonable representable string.
|
||||
///
|
||||
/// Meant to be used only for debugging or metrics-reporting purposes.
|
||||
fn maybe_utf8_bytes_to_string(id: &[u8]) -> Cow<str> {
|
||||
if let Ok(s) = std::str::from_utf8(&id[..]) {
|
||||
Cow::Borrowed(s)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user