mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Move the telemetry information to service (#2846)
* Move the telemetry information to service * Proper exit
This commit is contained in:
committed by
Gavin Wood
parent
ce302390dd
commit
68f4d11df3
@@ -31,7 +31,7 @@ use std::collections::HashMap;
|
||||
use futures::sync::mpsc;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use client::BlockchainEvents;
|
||||
use client::{BlockchainEvents, backend::Backend};
|
||||
use exit_future::Signal;
|
||||
use futures::prelude::*;
|
||||
use keystore::Store as Keystore;
|
||||
@@ -41,6 +41,8 @@ use primitives::Pair;
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{Header, SaturatedConversion};
|
||||
use substrate_executor::NativeExecutor;
|
||||
use network::SyncProvider;
|
||||
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
|
||||
use tel::{telemetry, SUBSTRATE_INFO};
|
||||
|
||||
pub use self::error::Error;
|
||||
@@ -305,11 +307,17 @@ impl<Components: components::Components> Service<Components> {
|
||||
{
|
||||
// extrinsic notifications
|
||||
let network = Arc::downgrade(&network);
|
||||
let transaction_pool_ = transaction_pool.clone();
|
||||
let events = transaction_pool.import_notification_stream()
|
||||
.for_each(move |_| {
|
||||
if let Some(network) = network.upgrade() {
|
||||
network.trigger_repropagate();
|
||||
}
|
||||
let status = transaction_pool_.status();
|
||||
telemetry!(SUBSTRATE_INFO; "txpool.import";
|
||||
"ready" => status.ready,
|
||||
"future" => status.future
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
.select(exit.clone())
|
||||
@@ -318,6 +326,56 @@ impl<Components: components::Components> Service<Components> {
|
||||
task_executor.spawn(events);
|
||||
}
|
||||
|
||||
// Periodically notify the telemetry.
|
||||
let transaction_pool_ = transaction_pool.clone();
|
||||
let client_ = client.clone();
|
||||
let network_ = network.clone();
|
||||
let mut sys = System::new();
|
||||
let self_pid = get_current_pid();
|
||||
task_executor.spawn(network.status().for_each(move |sync_status| {
|
||||
let info = client_.info();
|
||||
let best_number = info.chain.best_number.saturated_into::<u64>();
|
||||
let best_hash = info.chain.best_hash;
|
||||
let num_peers = sync_status.num_peers;
|
||||
let txpool_status = transaction_pool_.status();
|
||||
let finalized_number: u64 = info.chain.finalized_number.saturated_into::<u64>();
|
||||
let bandwidth_download = network_.average_download_per_sec();
|
||||
let bandwidth_upload = network_.average_upload_per_sec();
|
||||
|
||||
#[allow(deprecated)]
|
||||
let backend = (*client_).backend();
|
||||
let used_state_cache_size = match backend.used_state_cache_size(){
|
||||
Some(size) => size,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
// get cpu usage and memory usage of this process
|
||||
let (cpu_usage, memory) = if sys.refresh_process(self_pid) {
|
||||
let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed");
|
||||
(proc.cpu_usage(), proc.memory())
|
||||
} else { (0.0, 0) };
|
||||
|
||||
let network_state = network_.network_state();
|
||||
|
||||
telemetry!(
|
||||
SUBSTRATE_INFO;
|
||||
"system.interval";
|
||||
"network_state" => network_state,
|
||||
"peers" => num_peers,
|
||||
"height" => best_number,
|
||||
"best" => ?best_hash,
|
||||
"txcount" => txpool_status.ready,
|
||||
"cpu" => cpu_usage,
|
||||
"memory" => memory,
|
||||
"finalized_height" => finalized_number,
|
||||
"finalized_hash" => ?info.chain.finalized_hash,
|
||||
"bandwidth_download" => bandwidth_download,
|
||||
"bandwidth_upload" => bandwidth_upload,
|
||||
"used_state_cache_size" => used_state_cache_size,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}).select(exit.clone()).then(|_| Ok(())));
|
||||
|
||||
// RPC
|
||||
let system_info = rpc::apis::system::SystemInfo {
|
||||
|
||||
Reference in New Issue
Block a user