Skip to main content

parse_cpu_top

Function parse_cpu_top 

Source
pub fn parse_cpu_top(output: &str) -> Option<f64>
Expand description

Parse CPU idle percentage from Linux top -bn1 output.

Handles both modern procps-ng format (%Cpu(s): 2.3 us, ... 96.7 id) and older format (Cpu(s): 2.3%us, ... 96.7%id). Also handles Alpine BusyBox format (CPU: 4% usr 1% sys 94% idle).

Returns 100 - idle_percent as the used percentage.