From 1a1ce5485993095879856f09eff564b947917002 Mon Sep 17 00:00:00 2001 From: Yuta Katayama Date: Thu, 27 Feb 2020 13:52:46 +0900 Subject: [PATCH] Fix #8: Add new options "@sysstat_cpu_pused_format", "@sysstat_mem_pused_format" and "@sysstat_mem_pfree_format" --- readme.md | 10 ++++++++++ scripts/cpu.sh | 3 ++- scripts/mem.sh | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 2bd0295..1646ade 100644 --- a/readme.md +++ b/readme.md @@ -150,6 +150,16 @@ set -g @sysstat_mem_size_unit "G" If you choose `G` for size scale, output will have `%.1f` (1 digit after floating point), otherwise size is integer (4.5G, 1024M, 1232345K). +### Change percentage format + +You can change default percentage format. + +``` +set -g @sysstat_cpu_pused_format '%2.0f%%' +set -g @sysstat_mem_pused_format '%2.0f%%' +set -g @sysstat_mem_pfree_format '%2.0f%%' +``` + Thresholds and colored output --------------- Each metric output is colored by default. Colors vary depending on metric value. diff --git a/scripts/cpu.sh b/scripts/cpu.sh index adc2223..ff06a36 100755 --- a/scripts/cpu.sh +++ b/scripts/cpu.sh @@ -11,6 +11,7 @@ source "$CURRENT_DIR/helpers.sh" cpu_tmp_dir=$(tmux show-option -gqv "@sysstat_cpu_tmp_dir") cpu_view_tmpl=$(get_tmux_option "@sysstat_cpu_view_tmpl" 'CPU:#[fg=#{cpu.color}]#{cpu.pused}#[default]') +cpu_pused_format=$(get_tmux_option "@sysstat_cpu_pused_format" '%.1f%%') cpu_medium_threshold=$(get_tmux_option "@sysstat_cpu_medium_threshold" "30") cpu_stress_threshold=$(get_tmux_option "@sysstat_cpu_stress_threshold" "80") @@ -36,7 +37,7 @@ print_cpu_usage() { local cpu_color=$(get_cpu_color "$cpu_pused") local cpu_view="$cpu_view_tmpl" - cpu_view="${cpu_view//'#{cpu.pused}'/$(printf "%.1f%%" "$cpu_pused")}" + cpu_view="${cpu_view//'#{cpu.pused}'/$(printf "$cpu_pused_format" "$cpu_pused")}" cpu_view="${cpu_view//'#{cpu.color}'/$(echo "$cpu_color" | awk '{ print $1 }')}" cpu_view="${cpu_view//'#{cpu.color2}'/$(echo "$cpu_color" | awk '{ print $2 }')}" cpu_view="${cpu_view//'#{cpu.color3}'/$(echo "$cpu_color" | awk '{ print $3 }')}" diff --git a/scripts/mem.sh b/scripts/mem.sh index 6a032bf..7988aba 100755 --- a/scripts/mem.sh +++ b/scripts/mem.sh @@ -9,6 +9,8 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/helpers.sh" mem_view_tmpl=$(get_tmux_option "@sysstat_mem_view_tmpl" 'MEM:#[fg=#{mem.color}]#{mem.pused}#[default]') +mem_pused_format=$(get_tmux_option "@sysstat_mem_pused_format" '%.0f%%') +mem_pfree_format=$(get_tmux_option "@sysstat_mem_pfree_format" '%.0f%%') mem_medium_threshold=$(get_tmux_option "@sysstat_mem_medium_threshold" "75") mem_stress_threshold=$(get_tmux_option "@sysstat_mem_stress_threshold" "90") @@ -59,9 +61,9 @@ print_mem() { local mem_view="$mem_view_tmpl" mem_view="${mem_view//'#{mem.used}'/$(printf "$size_format" "$mem_used" "$size_unit")}" - mem_view="${mem_view//'#{mem.pused}'/$(printf "%.0f%%" "$mem_pused")}" + mem_view="${mem_view//'#{mem.pused}'/$(printf "$mem_pused_format" "$mem_pused")}" mem_view="${mem_view//'#{mem.free}'/$(printf "$size_format" "$mem_free" "$size_unit")}" - mem_view="${mem_view//'#{mem.pfree}'/$(printf "%.0f%%" "$mem_pfree")}" + mem_view="${mem_view//'#{mem.pfree}'/$(printf "$mem_pfree_format" "$mem_pfree")}" mem_view="${mem_view//'#{mem.total}'/$(printf "$size_format" "$mem_total" "$size_unit")}" mem_view="${mem_view//'#{mem.color}'/$(echo "$mem_color" | awk '{ print $1 }')}" mem_view="${mem_view//'#{mem.color2}'/$(echo "$mem_color" | awk '{ print $2 }')}"