From 78b4ab0414eb1c3b69a1fd9eae60f520e7fc79d2 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 22 Apr 2016 12:24:30 +0100 Subject: [PATCH 1/3] Improvements to load prompt, now reporting warning and critical at 50% and 70% cpu core utilisation --- powerlevel9k.zsh-theme | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d583eaab..4fd7ecf4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -578,30 +578,39 @@ prompt_ip() { prompt_load() { # The load segment can have three different states local current_state="unknown" + local cores + + if [[ "$OS" == "OSX" ]]; then + cores=$(sysctl -a | grep machdep.cpu) + else + cores=$(nproc) + fi + typeset -AH load_states load_states=( 'critical' 'red' 'warning' 'yellow' 'normal' 'green' ) + 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 - 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 # 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" - elif [[ "$load_avg_5min" -gt 3 ]]; then + elif [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.5") ]]; then current_state="warning" else current_state="normal" 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 From d2728f0dd1fd301f6de2250053485553673aafd3 Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 25 Apr 2016 07:08:36 +0100 Subject: [PATCH 2/3] Consolidated if statements and fixed OSX cpu cores command --- powerlevel9k.zsh-theme | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4fd7ecf4..0f321bc3 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -580,12 +580,6 @@ prompt_load() { local current_state="unknown" local cores - if [[ "$OS" == "OSX" ]]; then - cores=$(sysctl -a | grep machdep.cpu) - else - cores=$(nproc) - fi - typeset -AH load_states load_states=( 'critical' 'red' @@ -595,8 +589,10 @@ prompt_load() { if [[ "$OS" == "OSX" ]]; then load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) + cores=$(sysctl -n hw.physicalcpu) else load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) + cores=$(nproc) fi # Replace comma From 61a0cee4f513f71c17737abd2fe1d3d5e9aa67e7 Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 2 May 2016 15:35:43 +0100 Subject: [PATCH 3/3] Using logical CPUs, as it's a fairer reflection of CPU load --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0f321bc3..224e34cc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -589,7 +589,7 @@ prompt_load() { if [[ "$OS" == "OSX" ]]; then load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) - cores=$(sysctl -n hw.physicalcpu) + cores=$(sysctl -n hw.logicalcpu) else load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) cores=$(nproc)