Re-fix of psutil disk collection

pull/153/head
aristocratos 2020-06-23 19:01:09 +02:00
parent bd83b73871
commit bf1898c647
2 changed files with 17 additions and 10 deletions

24
bashtop
View File

@ -386,7 +386,7 @@ init_() { #? Collect needed information and set options before startig main loop
if [[ -n $curled ]] && command -v notify-send >/dev/null 2>&1; then notifier=1; else unset notifier; fi if [[ -n $curled ]] && command -v notify-send >/dev/null 2>&1; then notifier=1; else unset notifier; fi
#* Check if "iostat" command is available, if not, disable disk io stat collection #* Check if "iostat" command is available, if not, disable disk io stat collection
if [[ $use_psutil == false ]] && command -v iostat >/dev/null 2>&1; then has_iostat=1; else unset has_iostat; fi 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 number of cores and cpu threads
print -bg "#00" -fg "#30ff50" -r 1 -t "√" print -bg "#00" -fg "#30ff50" -r 1 -t "√"
@ -1371,7 +1371,7 @@ create_graph() { #? Create a graph from an array of percentage values, usage;
#* Create graph by walking through all values for each line, speed up by counting similar values and print once, when difference is met #* Create graph by walking through all values for each line, speed up by counting similar values and print once, when difference is met
while ((x<value_width)); do while ((x<value_width)); do
if [[ -z ${input_array[x]} ]] || ((input_array[x]<1)); then input_array[x]=0; fi if [[ -z ${input_array[x]} ]] || ((input_array[x]<1)) || ((${#input_array[x]}>3)); then input_array[x]=0; fi
#* Print empty space if current value is less than percentage for current line #* Print empty space if current value is less than percentage for current line
while ((x<value_width & input_array[x]*virt_height/100<next_value)); do while ((x<value_width & input_array[x]*virt_height/100<next_value)); do
@ -2264,13 +2264,13 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
done done
#* Get disk information #* Get disk information
local df_array df_line line_array dev_path dev_name iostat_var disk_read disk_write disk_io_string df_count=0 filtering psutil_on local df_line line_array dev_path dev_name iostat_var disk_read disk_write disk_io_string df_count=0 filtering psutil_on
local -a device_array iostat_array local -a device_array iostat_array df_array
unset 'disks_free[@]' 'disks_used[@]' 'disks_used_percent[@]' 'disks_total[@]' 'disks_name[@]' 'disks_free_percent[@]' 'disks_io[@]' unset 'disks_free[@]' 'disks_used[@]' 'disks_used_percent[@]' 'disks_total[@]' 'disks_name[@]' 'disks_free_percent[@]' 'disks_io[@]'
if [[ -n $psutil_disk_fail ]]; then psutil_on="false"; else psutil_on="$use_psutil"; fi if [[ -n $psutil_disk_fail ]]; then psutil_on="false"; else psutil_on="$use_psutil"; fi
if [[ $psutil_on == true ]]; then if [[ $psutil_on == true ]]; then
if [[ -n $disks_filter ]]; then filtering=", filtering='${disks_filter}'"; fi if [[ -n $disks_filter ]]; then filtering=", filtering='${disks_filter}'"; fi
py_command -a df_array "get_disks(exclude='squashfs'${filtering})" || psutil_disk_fail=1 if ! py_command -a df_array "get_disks(exclude='squashfs'${filtering})"; then psutil_disk_fail=1; psutil_on="false"; fi
fi fi
if [[ $psutil_on == false ]]; then if [[ $psutil_on == false ]]; then
readarray -t df_array < <(${df} -x squashfs -x tmpfs -x devtmpfs -x overlay 2>/dev/null || true) readarray -t df_array < <(${df} -x squashfs -x tmpfs -x devtmpfs -x overlay 2>/dev/null || true)
@ -2658,7 +2658,9 @@ collect_processes_psutil() {
unset 'proc_array[@]' unset 'proc_array[@]'
py_command -a proc_array "get_proc(sorting='${proc_sorting}', tree=${proc_tree^}, prog_len=${prog_len}, arg_len=${arg_len}, search='${filter}', reverse=${proc_reversed^}, proc_per_cpu=${proc_per_core^})" || return if ! py_command -a proc_array "get_proc(sorting='${proc_sorting}', tree=${proc_tree^}, prog_len=${prog_len}, arg_len=${arg_len}, search='${filter}', reverse=${proc_reversed^}, proc_per_cpu=${proc_per_core^})"; then
proc_array=(""); return
fi
proc_array[0]="${proc_array[0]/ ${selected}/${symbol}${selected}}" proc_array[0]="${proc_array[0]/ ${selected}/${symbol}${selected}}"
proc[pages]=$(( (${#proc_array[@]}-1)/(height-3)+1 )) proc[pages]=$(( (${#proc_array[@]}-1)/(height-3)+1 ))
@ -4795,7 +4797,7 @@ fi
if [[ $use_psutil == true ]]; then if [[ $use_psutil == true ]]; then
py_command() { py_command() {
if [[ -n $failed_pipe ]]; then return; fi if [[ -n $failed_pipe ]]; then return; fi
local arr var output cmd pyerr ln local arr var output cmd pyerr=${py_error} ln
case $1 in case $1 in
"quit") "quit")
echo "quit" >&${pycoproc[1]} 2>/dev/null || true echo "quit" >&${pycoproc[1]} 2>/dev/null || true
@ -4814,10 +4816,12 @@ if [[ $use_psutil == true ]]; then
else pyout=(); fi else pyout=(); fi
while IFS= read -r -u ${pycoproc[0]} -t 1 output; do #2>/dev/null while IFS= read -r -u ${pycoproc[0]} -t 1 output; do #2>/dev/null
if [[ $output == '/EOL' ]]; then break; fi if [[ $output == '/EOL' ]]; then break; fi
if [[ $output == '/ERROR' || -n $failed_pipe ]]; then py_error=1; py_out=""; return 1; fi if [[ -n $failed_pipe ]]; then py_out=""; return 1; fi
if [[ $output == '/ERROR' ]]; then ((++py_error)); unset arr var; fi
if [[ -n $arr ]]; then pyout+=("${output}") if [[ -n $arr ]]; then pyout+=("${output}")
elif [[ -n $var ]]; then pyout+="${output}${ln:+\n}"; fi elif [[ -n $var ]]; then pyout+="${output}${ln:+\n}"; fi
done done
if ((py_error>pyerr)); then py_out=""; return 1; fi
if [[ -n $ln ]]; then printf -v pyout "%b" "${pyout}"; fi if [[ -n $ln ]]; then printf -v pyout "%b" "${pyout}"; fi
return 0 return 0
} }
@ -5211,11 +5215,13 @@ while command != 'quit':
exec(command) exec(command)
except Exception as e: except Exception as e:
pass pass
print('\n', '/ERROR') print()
print('/ERROR')
print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr) print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr)
else: else:
continue continue
print('/EOL') print('/EOL')
#print(f'{command}', file=sys.stderr)
EOF EOF
fi fi

View File

@ -388,7 +388,8 @@ while command != 'quit':
exec(command) exec(command)
except Exception as e: except Exception as e:
pass pass
print('\n', '/ERROR') print()
print('/ERROR')
print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr) print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr)
else: else:
continue continue