mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 16:01:04 +00:00
Refactor & detach network metrics. (#6986)
* Refactor sc-network/service metrics. 1. Aggregate sc-network metrics into a submodule, introducing two more sourced metrics to avoid duplicate atomics. 2. Decouple periodic sc-service network metrics from other metrics, so that they can be updated independently. * Update client/service/src/metrics.rs * Update client/service/src/metrics.rs
This commit is contained in:
@@ -126,24 +126,37 @@ impl RpcHandlers {
|
||||
/// Sinks to propagate network status updates.
|
||||
/// For each element, every time the `Interval` fires we push an element on the sender.
|
||||
#[derive(Clone)]
|
||||
pub struct NetworkStatusSinks<Block: BlockT>(
|
||||
Arc<status_sinks::StatusSinks<(NetworkStatus<Block>, NetworkState)>>,
|
||||
);
|
||||
pub struct NetworkStatusSinks<Block: BlockT> {
|
||||
status: Arc<status_sinks::StatusSinks<NetworkStatus<Block>>>,
|
||||
state: Arc<status_sinks::StatusSinks<NetworkState>>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> NetworkStatusSinks<Block> {
|
||||
fn new(
|
||||
sinks: Arc<status_sinks::StatusSinks<(NetworkStatus<Block>, NetworkState)>>
|
||||
) -> Self {
|
||||
Self(sinks)
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
status: Arc::new(status_sinks::StatusSinks::new()),
|
||||
state: Arc::new(status_sinks::StatusSinks::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a receiver that periodically receives a status of the network.
|
||||
pub fn network_status(&self, interval: Duration)
|
||||
-> TracingUnboundedReceiver<(NetworkStatus<Block>, NetworkState)> {
|
||||
/// Returns a receiver that periodically yields a [`NetworkStatus`].
|
||||
pub fn status_stream(&self, interval: Duration)
|
||||
-> TracingUnboundedReceiver<NetworkStatus<Block>>
|
||||
{
|
||||
let (sink, stream) = tracing_unbounded("mpsc_network_status");
|
||||
self.0.push(interval, sink);
|
||||
self.status.push(interval, sink);
|
||||
stream
|
||||
}
|
||||
|
||||
/// Returns a receiver that periodically yields a [`NetworkState`].
|
||||
pub fn state_stream(&self, interval: Duration)
|
||||
-> TracingUnboundedReceiver<NetworkState>
|
||||
{
|
||||
let (sink, stream) = tracing_unbounded("mpsc_network_state");
|
||||
self.state.push(interval, sink);
|
||||
stream
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Sinks to propagate telemetry connection established events.
|
||||
@@ -319,20 +332,16 @@ async fn build_network_future<
|
||||
// the network.
|
||||
_ = (&mut network).fuse() => {}
|
||||
|
||||
// At a regular interval, we send the state of the network on what is called
|
||||
// the "status sinks".
|
||||
ready_sink = status_sinks.0.next().fuse() => {
|
||||
let status = NetworkStatus {
|
||||
sync_state: network.sync_state(),
|
||||
best_seen_block: network.best_seen_block(),
|
||||
num_sync_peers: network.num_sync_peers(),
|
||||
num_connected_peers: network.num_connected_peers(),
|
||||
num_active_peers: network.num_active_peers(),
|
||||
total_bytes_inbound: network.total_bytes_inbound(),
|
||||
total_bytes_outbound: network.total_bytes_outbound(),
|
||||
};
|
||||
let state = network.network_state();
|
||||
ready_sink.send((status, state));
|
||||
// At a regular interval, we send high-level status as well as
|
||||
// detailed state information of the network on what are called
|
||||
// "status sinks".
|
||||
|
||||
status_sink = status_sinks.status.next().fuse() => {
|
||||
status_sink.send(network.status());
|
||||
}
|
||||
|
||||
state_sink = status_sinks.state.next().fuse() => {
|
||||
state_sink.send(network.network_state());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user