diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 3a14f98546690160355369cbe910049359f6764b..e044fbd7d15273aa7352990c65029d495fb56b55 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2680,6 +2680,7 @@ dependencies = [ "substrate-runtime-primitives 0.1.0", "substrate-service 0.3.0", "substrate-telemetry 0.3.0", + "sysinfo 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3328,6 +3329,17 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sysinfo" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "take" version = "0.1.0" @@ -4222,6 +4234,7 @@ dependencies = [ "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum subtle 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc7f6353c2ee5407358d063a14cccc1630804527090a6fb5a9489ce4924280fb" "checksum syn 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6dfd71b2be5a58ee30a6f8ea355ba8290d397131c00dfa55c3d34e6e13db5101" +"checksum sysinfo 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "394abcf30852ac00878ab01642b13668db48d166d945f250c7bdbb9e12d75ad0" "checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c63f48baada5c52e65a29eef93ab4f8982681b67f9e8d29c7b05abcfec2b9ffe" diff --git a/substrate/substrate/cli/Cargo.toml b/substrate/substrate/cli/Cargo.toml index 723c568ba325be49ed8e0a9b5d6d256bd2a379d3..176d59bbe75d2e9f1b55f09faa48c8bd3a424c62 100644 --- a/substrate/substrate/cli/Cargo.toml +++ b/substrate/substrate/cli/Cargo.toml @@ -22,6 +22,7 @@ tokio = "0.1.7" futures = "0.1.17" fdlimit = "0.1" exit-future = "0.1" +sysinfo = "0.5.7" substrate-client = { path = "../../substrate/client" } substrate-extrinsic-pool = { path = "../../substrate/extrinsic-pool" } substrate-network = { path = "../../substrate/network" } diff --git a/substrate/substrate/cli/src/informant.rs b/substrate/substrate/cli/src/informant.rs index d980e74bb814f3157b1c026e7ed339d92beb771b..2cc61a8e83e48f209deee649b6c23a921aa1e85f 100644 --- a/substrate/substrate/cli/src/informant.rs +++ b/substrate/substrate/cli/src/informant.rs @@ -22,6 +22,7 @@ use futures::{Future, Stream}; use service::{Service, Components}; use tokio::runtime::TaskExecutor; use tokio::timer::Interval; +use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use network::{SyncState, SyncProvider}; use client::BlockchainEvents; use runtime_primitives::traits::{Header, As}; @@ -41,6 +42,9 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe let txpool = service.extrinsic_pool(); let mut last_number = None; + let mut sys = System::new(); + let self_pid = get_current_pid(); + let display_notifications = interval.map_err(|e| debug!("Timer error: {:?}", e)).for_each(move |_| { let sync_status = network.status(); @@ -65,17 +69,27 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe Colour::White.paint(format!("{}", best_number)), hash ); + + // 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) }; + telemetry!( "system.interval"; "status" => format!("{}{}", status, target), "peers" => num_peers, "height" => best_number, "best" => ?hash, - "txcount" => txpool_status.transaction_count + "txcount" => txpool_status.transaction_count, + "cpu" => cpu_usage, + "memory" => memory ); } else { warn!("Error getting best block information"); } + Ok(()) }); diff --git a/substrate/substrate/cli/src/lib.rs b/substrate/substrate/cli/src/lib.rs index a1064cccc44001ff91ef3f9ef8ad5cd818fade2f..f2dee51e454a92589a61c539a557cbe66e2bd23b 100644 --- a/substrate/substrate/cli/src/lib.rs +++ b/substrate/substrate/cli/src/lib.rs @@ -30,6 +30,7 @@ extern crate futures; extern crate tokio; extern crate names; extern crate backtrace; +extern crate sysinfo; extern crate substrate_client as client; extern crate substrate_network as network; diff --git a/substrate/substrate/telemetry/src/lib.rs b/substrate/substrate/telemetry/src/lib.rs index 4782f244e11b5ca8601fcf0e7c2e1c1bc93cba2d..1054b7b397d4ee887b455c778b868ba6d9ab9230 100644 --- a/substrate/substrate/telemetry/src/lib.rs +++ b/substrate/substrate/telemetry/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see <http://www.gnu.org/licenses/>. -//! Telemtetry utils. +//! Telemetry utils. //! //! `telemetry` macro be used from whereever in the Substrate codebase //! in order to send real-time logging information to the telemetry