1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-14 00:50:08 +00:00

Improvements to load prompt, now reporting warning and critical at 50% and 70% cpu core utilisation

This commit is contained in:
David McKay 2016-04-22 12:24:30 +01:00
parent 24fac49050
commit 78b4ab0414

View file

@ -578,30 +578,39 @@ prompt_ip() {
prompt_load() { prompt_load() {
# The load segment can have three different states # The load segment can have three different states
local current_state="unknown" local current_state="unknown"
local cores
if [[ "$OS" == "OSX" ]]; then
cores=$(sysctl -a | grep machdep.cpu)
else
cores=$(nproc)
fi
typeset -AH load_states typeset -AH load_states
load_states=( load_states=(
'critical' 'red' 'critical' 'red'
'warning' 'yellow' 'warning' 'yellow'
'normal' 'green' 'normal' 'green'
) )
if [[ "$OS" == "OSX" ]]; then if [[ "$OS" == "OSX" ]]; then
load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1)
else else
load_avg_5min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
fi fi
# Replace comma # Replace comma
load_avg_5min=${load_avg_5min//,/.} load_avg_1min=${load_avg_1min//,/.}
if [[ "$load_avg_5min" -gt 10 ]]; then if [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
current_state="critical" current_state="critical"
elif [[ "$load_avg_5min" -gt 3 ]]; then elif [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
current_state="warning" current_state="warning"
else else
current_state="normal" current_state="normal"
fi fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_1min" 'LOAD_ICON'
} }
# Node version # Node version