mirror of https://github.com/aristocratos/bashtop
added disks read/write stats
parent
ad7ea31a86
commit
d6af79fcd1
63
bashtop
63
bashtop
|
@ -138,7 +138,7 @@ menu_quit_selected=(
|
|||
"║═╬╗║ ║ ║ ║ "
|
||||
"╚═╝╚╚═╝ ╩ ╩ ")
|
||||
|
||||
declare -A cpu mem swap proc net box theme
|
||||
declare -A cpu mem swap proc net box theme disks
|
||||
declare -a cpu_usage cpu_graph_a cpu_graph_b color_meter color_temp_graph color_cpu color_cpu_graph cpu_history color_mem_graph color_swap_graph
|
||||
declare -a mem_history swap_history net_history_download net_history_upload mem_graph swap_graph proc_array download_graph upload_graph trace_array
|
||||
declare resized=1 size_error clock tty_width tty_height hex="16#" cpu_p_box swap_on=1 draw_out esc_character boxes_out last_screen clock_out update_string
|
||||
|
@ -148,9 +148,9 @@ declare -a save_array=(${options_array[*]/net_totals_reset/})
|
|||
declare -a sorting=( "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu responsive" )
|
||||
declare -a pid_history detail_graph detail_history detail_mem_history
|
||||
declare time_left timestamp_start timestamp_end timestamp_input_start timestamp_input_end time_string mem_out proc_misc prev_screen pause_screen filter input_to_filter
|
||||
declare no_epoch proc_det proc_misc2 sleeping=0 detail_mem_graph proc_det2 proc_out curled git_version
|
||||
declare no_epoch proc_det proc_misc2 sleeping=0 detail_mem_graph proc_det2 proc_out curled git_version has_iostat
|
||||
declare esc_character tab backspace sleepy late_update skip_process_draw winches quitting theme_int
|
||||
declare -a disks_free disks_total disks_name disks_free_percent saved_key themes
|
||||
declare -a disks_free disks_total disks_name disks_free_percent disks_io saved_key themes
|
||||
printf -v esc_character "\u1b"
|
||||
printf -v tab "\u09"
|
||||
printf -v backspace "\u7F"
|
||||
|
@ -216,6 +216,9 @@ init_() { #? Collect needed information and set options before startig main loop
|
|||
#* Check if "curl" command is available, if not, disable update check and theme downloads
|
||||
if command -v curl >/dev/null 2>&1; then curled=1; else unset curled; fi
|
||||
|
||||
#* Check if "iostat" command is available, if not, disable disk io stat collection
|
||||
if command -v iostat >/dev/null 2>&1; then has_iostat=1; else unset has_iostat; fi
|
||||
|
||||
#* Get number of cores and cpu threads
|
||||
get_cpu_info
|
||||
|
||||
|
@ -647,13 +650,14 @@ is_hex() { #? Check if value(s) is hexadecimal
|
|||
|
||||
floating_humanizer() { #? Convert integer to floating point and scale up in steps of 1024 to highest positive unit
|
||||
#? Usage: floating_humanizer <-b,-bit|-B,-Byte> [-ps,-per-second] [-s,-start "1024 multiplier start"] [-v,-variable-output] <input>
|
||||
local value selector per_second unit_mult decimals out_var ext_var
|
||||
local value selector per_second unit_mult decimals out_var ext_var short sep=" "
|
||||
local -a unit
|
||||
until (($#==0)); do
|
||||
case "$1" in
|
||||
-b|-bit) unit=(bit Kib Mib Gib Tib Pib); unit_mult=8;;
|
||||
-B|-Byte) unit=(Byte KiB MiB GiB TiB PiB); unit_mult=1;;
|
||||
-ps|-per-second) per_second=1;;
|
||||
-short) short=1; sep="";;
|
||||
-s|-start) selector="$2"; shift;;
|
||||
-v|-variable-output) local -n out_var="$2"; ext_var=1; shift;;
|
||||
*) if is_int "$1"; then value=$1; break; fi;;
|
||||
|
@ -674,7 +678,7 @@ floating_humanizer() { #? Convert integer to floating point and scale up in ste
|
|||
((++selector))
|
||||
done
|
||||
|
||||
if ((${#value}<5 & ${#value}>=2 & selector>0)); then
|
||||
if [[ -z $short ]] && ((${#value}<5 & ${#value}>=2 & selector>0)); then
|
||||
decimals=$((5-${#value}))
|
||||
value="${value::-2}.${value:(-${decimals})}"
|
||||
elif ((${#value}>=2)); then
|
||||
|
@ -682,7 +686,7 @@ floating_humanizer() { #? Convert integer to floating point and scale up in ste
|
|||
fi
|
||||
fi
|
||||
|
||||
out_var="${value} ${unit[$selector]}${per_second}"
|
||||
out_var="${value}${sep}${unit[$selector]::${short:-${#unit[$selector]}}}${per_second}"
|
||||
if [[ -z $ext_var ]]; then echo -n "${out_var}"; fi
|
||||
}
|
||||
|
||||
|
@ -1491,7 +1495,7 @@ collect_cpu_temps() { #? Collect cpu temperatures
|
|||
collect_mem() { #? Collect memory information from "/proc/meminfo"
|
||||
((++mem[counter]))
|
||||
|
||||
if ((mem[counter]<5)); then return; fi
|
||||
if ((mem[counter]<4)); then return; fi
|
||||
mem[counter]=0
|
||||
|
||||
local i tmp value array mem_info height=$((box[mem_height]-2)) skip filter_value
|
||||
|
@ -1535,8 +1539,9 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
|
|||
done
|
||||
|
||||
#* Get disk information from "df" command
|
||||
local df_array df_line line_array
|
||||
unset 'disks_free[@]' 'disks_used[@]' 'disks_used_percent[@]' 'disks_total[@]' 'disks_name[@]' 'disks_free_percent[@]'
|
||||
local df_array df_line line_array dev_path dev_name iostat_var disk_read disk_write disk_io_string
|
||||
local -a device_array iostat_array
|
||||
unset 'disks_free[@]' 'disks_used[@]' 'disks_used_percent[@]' 'disks_total[@]' 'disks_name[@]' 'disks_free_percent[@]' 'disks_io[@]'
|
||||
readarray -t df_array < <(df -x squashfs -x tmpfs -x devtmpfs -x overlay)
|
||||
for df_line in "${df_array[@]:1}"; do
|
||||
line_array=(${df_line})
|
||||
|
@ -1558,6 +1563,32 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
|
|||
disks_used_percent+=("${line_array[4]%'%'}")
|
||||
disks_free+=("$(floating_humanizer -s 1 -B ${line_array[3]})")
|
||||
disks_free_percent+=("$((100-${line_array[4]%'%'}))")
|
||||
|
||||
#* Get read/write stats for disk if "iostat" is available
|
||||
if [[ -n $has_iostat ]]; then
|
||||
dev_name="${line_array[0]##*/}"
|
||||
dev_path="${line_array[0]%${dev_name}}"
|
||||
if [[ ${dev_name::2} == "md" ]]; then dev_name="${dev_name::3}"; fi
|
||||
unset iostat_var disk_io_string 'iostat_array[@]'
|
||||
read -r iostat_var < <(iostat -dkz --dec=0 "${dev_path}${dev_name}" | tail -n +4)
|
||||
iostat_array=(${iostat_var})
|
||||
if [[ -n ${iostat_array[-2]} ]]; then
|
||||
|
||||
disk_read=$((iostat_array[-2]-${disks[${dev_name}_read]:-${iostat_array[-2]}}))
|
||||
disk_write=$((iostat_array[-1]-${disks[${dev_name}_write]:-${iostat_array[-1]}}))
|
||||
|
||||
if ((box[m_width2]>25)); then
|
||||
if ((disk_read>0)); then disk_io_string="▲$(floating_humanizer -s 1 -short -B ${disk_read}) "; fi
|
||||
if ((disk_write>0)); then disk_io_string+="▼$(floating_humanizer -s 1 -short -B ${disk_write})"; fi
|
||||
elif ((disk_read+disk_write>0)); then
|
||||
disk_io_string+="▼▲$(floating_humanizer -s 1 -short -B $((disk_read+disk_write)))"
|
||||
fi
|
||||
|
||||
disks[${dev_name}_read]="${iostat_array[-2]}"
|
||||
disks[${dev_name}_write]="${iostat_array[-1]}"
|
||||
fi
|
||||
disks_io+=("${disk_io_string:-0}")
|
||||
fi
|
||||
else
|
||||
unset 'disks_name[-1]'
|
||||
disks_name=("${disks_name[@]}")
|
||||
|
@ -2219,7 +2250,7 @@ draw_mem() { #? Draw mem, swap and disk statistics
|
|||
|
||||
|
||||
#* Create text and meters for disks and adapt sizes based on available height
|
||||
local disk_num disk_name disk_value v_height2
|
||||
local disk_num disk_name disk_value v_height2 just_val name_len
|
||||
y_pos=$m_line
|
||||
m_col=$((m_col+m_width))
|
||||
m_width=${box[m_width2]}
|
||||
|
@ -2229,8 +2260,16 @@ draw_mem() { #? Draw mem, swap and disk statistics
|
|||
for disk_name in "${disks_name[@]}"; do
|
||||
if ((y_pos>m_line+height-2)); then break; fi
|
||||
|
||||
#* Print folder disk is mounted on and total size in humanized base 2 bytes
|
||||
print -v mem_out -m $((y_pos++)) $m_col -rs -fg ${theme[title]} -b -jl 9 -t "${disks_name[disk_num]::10}" -jr $((m_width-11)) -t "${disks_total[disk_num]::$((m_width-11))}"
|
||||
#* Print folder disk is mounted on, total size in humanized base 2 bytes and io stats if enabled
|
||||
print -v mem_out -m $((y_pos++)) $m_col -rs -fg ${theme[title]} -b -t "${disks_name[disk_num]::10}"
|
||||
name_len=${#disks_name[disk_num]}; if ((name_len>10)); then name_len=10; fi
|
||||
if [[ -n $has_iostat && ${disks_io[disk_num]} != "0" ]] && ((m_width-11-name_len>6)); then
|
||||
print -v mem_out -jc $((m_width-name_len-10)) -rs -fg ${theme[main_fg]} -t "${disks_io[disk_num]::$((m_width-10-name_len))}"
|
||||
just_val=8
|
||||
else
|
||||
just_val=$((m_width-name_len-2))
|
||||
fi
|
||||
print -v mem_out -jr ${just_val} -fg ${theme[title]} -b -t "${disks_total[disk_num]::$((m_width-11))}"
|
||||
|
||||
for value in "used" "free"; do
|
||||
if ((height<v_height*3)) && [[ $value == "free" ]]; then break; fi
|
||||
|
|
Loading…
Reference in New Issue