send memory usage and cpu usage to telemetry (#499)

* send memory usage and cpu usage to telemetry

Fixes #443, however, it doesn't send IO usage, as it's not available in
this crate.

* fixes according to Gav's comments

* fix grumbles, send basictypes in telemetry
This commit is contained in:
Guanqun Lu
2018-08-15 16:04:44 +08:00
committed by Gav Wood
parent 548332da4f
commit bfbe1fe18b
5 changed files with 31 additions and 2 deletions
+1
View File
@@ -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" }
+15 -1
View File
@@ -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(())
});
+1
View File
@@ -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;
+1 -1
View File
@@ -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