From 7185eeac10665d5e4bd714fc2f16d37569a6bccf Mon Sep 17 00:00:00 2001 From: hydai Date: Tue, 29 Aug 2023 11:09:36 +0800 Subject: [PATCH] wasm: collect cgroup metrics as stats in wasmedge Signed-off-by: hydai --- wasm/src/wasmedge.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wasm/src/wasmedge.rs b/wasm/src/wasmedge.rs index a5c97d14..a4bb6c8a 100644 --- a/wasm/src/wasmedge.rs +++ b/wasm/src/wasmedge.rs @@ -35,7 +35,7 @@ use containerd_shim::{ error::Error, io::Stdio, monitor::{Subject, Topic}, - other_error, + other, other_error, processes::Process, protos::{cgroups::metrics::Metrics, shim::oci::Options, types::task::ProcessInfo}, ExitSignal, @@ -230,10 +230,18 @@ impl ProcessLifecycle for WasmEdgeInitLifecycle { )) } - async fn stats(&self, _p: &InitProcess) -> containerd_shim::Result { - Err(Error::Unimplemented( - "exec not supported for wasm containers".to_string(), - )) + async fn stats(&self, p: &InitProcess) -> containerd_shim::Result { + debug!("get stats of process {}", p.pid); + if p.pid <= 0 { + return Err(other!( + "failed to collect metrics because init process is {}", + p.pid + )); + } + // Because Wasm Applications execute the instructions inside the host Wasm + // Runtime, we should read the metrics from Cgroup for the CPU, memory, + // and filesystem usage. + containerd_shim::cgroup::collect_metrics(p.pid as u32) } async fn ps(&self, p: &InitProcess) -> containerd_shim::Result> {