Added usage, and temperature monitoring, gave GPU its own box and the option to disable GPUtil

pull/237/head
energizerbee 2023-08-10 22:12:20 -07:00
parent 2b6eca2d32
commit 2927888a1b
5 changed files with 272 additions and 42 deletions

BIN
Imgs/gpu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

View File

@ -27,6 +27,7 @@ Get it at https://github.com/aristocratos/btop
## Index ## Index
* [Documents](#documents) * [Documents](#documents)
* [GPU Monitoring](#gpu-monitoring)
* [Description](#description) * [Description](#description)
* [Features](#features) * [Features](#features)
* [Themes](#themes) * [Themes](#themes)
@ -48,6 +49,39 @@ Get it at https://github.com/aristocratos/btop
#### [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) #### [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
## GPU Monitoring
GPU monitor shows GPU usage, memory usage, and temperature.
#### Note
GPUtil uses nvidia-smi as a dependency, the package may not work with some graphics cards
(namely AMD cards).
#### Dependencies for GPU monitoring
For GPU collection, the python packages psutil, and GPUtil are required as well as nvidia-smi.
>Install nvidia-smi (Debian/Ubuntu based see installation section for other distros)
``` bash
sudo apt-get install nvidia-smi
```
>Install psutil and GPUtil if not already installed
``` bash
sudo python3 -m pip install psutil
```
``` bash
sudo python3 -m pip install GPUtil
```
#### Note
Be sure to turn on use psutil and use GPUtil in the options menu of Bashtop.
## Description ## Description
Resource monitor that shows usage and stats for processor, memory, disks, network and processes. Resource monitor that shows usage and stats for processor, memory, disks, network and processes.

235
bashtop
View File

@ -207,8 +207,8 @@ menu_quit_selected=(
"╚═╝╚╚═╝ ╩ ╩ ") "╚═╝╚╚═╝ ╩ ╩ ")
declare -A cpu mem gpu swap proc net box theme disks declare -A cpu mem gpu 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 cpu_usage gpu_usage cpu_graph_a cpu_graph_b gpu_graph_a gpu_graph_b color_meter color_temp_graph color_cpu color_cpu_graph cpu_history color_gpu_graph color_mem_graph color_swap_graph
declare -a mem_history swap_history net_history_download net_history_upload mem_graph gpu_graph swap_graph proc_array download_graph upload_graph trace_array declare -a mem_history swap_history gpu_history net_history_download net_history_upload mem_graph gpu_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 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
declare -a options_array=("color_theme" "update_ms" "use_psutil" "use_GPUtil" "proc_sorting" "proc_tree" "check_temp" "draw_clock" "background_update" "custom_cpu_name" declare -a options_array=("color_theme" "update_ms" "use_psutil" "use_GPUtil" "proc_sorting" "proc_tree" "check_temp" "draw_clock" "background_update" "custom_cpu_name"
"proc_per_core" "proc_reversed" "proc_gradient" "disks_filter" "hires_graphs" "net_totals_reset" "update_check" "error_logging") "proc_per_core" "proc_reversed" "proc_gradient" "disks_filter" "hires_graphs" "net_totals_reset" "update_check" "error_logging")
@ -255,7 +255,8 @@ declare -A graph_symbol_down='(
[4_0]=⡇ [4_1]=⡏ [4_2]=⡟ [4_3]=⡿ [4_4]=⣿ [4_0]=⡇ [4_1]=⡏ [4_2]=⡟ [4_3]=⡿ [4_4]=⣿
)' )'
declare -A graph declare -A graph
box[boxes]="cpu mem net processes"
box[boxes]="cpu mem net processes gpu"
cpu[threads]=0 cpu[threads]=0
@ -356,6 +357,10 @@ init_() { #? Collect needed information and set options before startig main loop
print -m $(( (tty_height/2-3)+stx++ )) 0 -bg "#00" -fg "#cc" -c -b "Checking cpu..." print -m $(( (tty_height/2-3)+stx++ )) 0 -bg "#00" -fg "#cc" -c -b "Checking cpu..."
get_cpu_info get_cpu_info
print -bg "#00" -fg "#30ff50" -r 1 -t "√"
print -m $(( (tty_height/2-3)+stx++ )) 0 -bg "#00" -fg "#cc" -c -b "Checking gpu..."
get_gpu_info
#* Set graph resolution #* Set graph resolution
graph[hires]="${hires_graphs}" graph[hires]="${hires_graphs}"
@ -480,16 +485,16 @@ init_() { #? Collect needed information and set options before startig main loop
} }
color_init_() { #? Check for theme file and set colors color_init_() { #? Check for theme file and set colors
local main_bg="" main_fg="#cc" title="#ee" hi_fg="#90" inactive_fg="#40" cpu_box="#3d7b46" mem_box="#8a882e" net_box="#423ba5" proc_box="#923535" proc_misc="#0de756" selected_bg="#7e2626" selected_fg="#ee" local main_bg="" main_fg="#cc" title="#ee" hi_fg="#90" inactive_fg="#40" cpu_box="#3d7b46" mem_box="#8a882e" gpu_box="#1433a6" net_box="#423ba5" proc_box="#923535" proc_misc="#0de756" selected_bg="#7e2626" selected_fg="#ee"
local temp_start="#4897d4" temp_mid="#5474e8" temp_end="#ff40b6" cpu_start="#50f095" cpu_mid="#f2e266" cpu_end="#fa1e1e" div_line="#30" local temp_start="#4897d4" temp_mid="#5474e8" temp_end="#ff40b6" cpu_start="#50f095" cpu_mid="#f2e266" cpu_end="#fa1e1e" div_line="#30" gpu_start='#00aeff' gpu_mid='#0037ff' gpu_end='#fa1e1e'
local free_start="#223014" free_mid="#b5e685" free_end="#dcff85" cached_start="#0b1a29" cached_mid="#74e6fc" cached_end="#26c5ff" available_start="#292107" available_mid="#ffd77a" available_end="#ffb814" local free_start="#223014" free_mid="#b5e685" free_end="#dcff85" cached_start="#0b1a29" cached_mid="#74e6fc" cached_end="#26c5ff" available_start="#292107" available_mid="#ffd77a" available_end="#ffb814"
local used_start="#3b1f1c" used_mid="#d9626d" used_end="#ff4769" download_start="#231a63" download_mid="#4f43a3" download_end="#b0a9de" upload_start="#510554" upload_mid="#7d4180" upload_end="#dcafde" local used_start="#3b1f1c" used_mid="#d9626d" used_end="#ff4769" download_start="#231a63" download_mid="#4f43a3" download_end="#b0a9de" upload_start="#510554" upload_mid="#7d4180" upload_end="#dcafde"
local hex2rgb color_name array_name this_color main_fg_dec sourced theme_unset local hex2rgb color_name array_name this_color main_fg_dec sourced theme_unset
local -i i y local -i i y
local -A rgb local -A rgb
local -a dec_test local -a dec_test
local -a convert_color=("main_bg" "temp_start" "temp_mid" "temp_end" "cpu_start" "cpu_mid" "cpu_end" "upload_start" "upload_mid" "upload_end" "download_start" "download_mid" "download_end" "used_start" "used_mid" "used_end" "available_start" "available_mid" "available_end" "cached_start" "cached_mid" "cached_end" "free_start" "free_mid" "free_end" "proc_misc" "main_fg_dec") local -a convert_color=("main_bg" "temp_start" "temp_mid" "temp_end" "cpu_start" "cpu_mid" "cpu_end" "gpu_start" "gpu_mid" "gpu_end" "upload_start" "upload_mid" "upload_end" "download_start" "download_mid" "download_end" "used_start" "used_mid" "used_end" "available_start" "available_mid" "available_end" "cached_start" "cached_mid" "cached_end" "free_start" "free_mid" "free_end" "proc_misc" "main_fg_dec")
local -a set_color=("main_fg" "title" "hi_fg" "div_line" "inactive_fg" "selected_fg" "selected_bg" "cpu_box" "mem_box" "net_box" "proc_box") local -a set_color=("main_fg" "title" "hi_fg" "div_line" "inactive_fg" "selected_fg" "selected_bg" "cpu_box" "mem_box" "gpu_box" "net_box" "proc_box")
for theme_unset in ${!theme[@]}; do for theme_unset in ${!theme[@]}; do
unset 'theme[${theme_unset}]' unset 'theme[${theme_unset}]'
@ -535,11 +540,12 @@ color_init_() { #? Check for theme file and set colors
box[cpu_color]="${theme[cpu_box]}" box[cpu_color]="${theme[cpu_box]}"
box[mem_color]="${theme[mem_box]}" box[mem_color]="${theme[mem_box]}"
box[gpu_color]="${theme[gpu_box]}"
box[net_color]="${theme[net_box]}" box[net_color]="${theme[net_box]}"
box[processes_color]="${theme[proc_box]}" box[processes_color]="${theme[proc_box]}"
#* Create color arrays from one, two or three color gradient, 100 values in each #* Create color arrays from one, two or three color gradient, 100 values in each
for array_name in "temp" "cpu" "upload" "download" "used" "available" "cached" "free"; do for array_name in "temp" "cpu" "gpu" "upload" "download" "used" "available" "cached" "free"; do
local -n color_array="color_${array_name}_graph" local -n color_array="color_${array_name}_graph"
local -a rgb_start=(${theme[${array_name}_start]}) rgb_mid=(${theme[${array_name}_mid]}) rgb_end=(${theme[${array_name}_end]}) local -a rgb_start=(${theme[${array_name}_start]}) rgb_mid=(${theme[${array_name}_mid]}) rgb_end=(${theme[${array_name}_end]})
local pf_calc middle=1 local pf_calc middle=1
@ -910,6 +916,13 @@ get_cpu_info() {
fi fi
} }
get_gpu_info(){
if [[ $use_GPUtil == true ]]; then
py_command -v gpu[model] "get_gpu_name()"
py_command -v gpu[driver] "get_gpu_driver()"
fi
}
get_value() { #? Get a value from a file, variable or array by searching for a non spaced "key name" on the same line get_value() { #? Get a value from a file, variable or array by searching for a non spaced "key name" on the same line
local match line_pos=1 int reg key all tmp_array input found input_line line_array line_val ext_var line_nr current_line match_key math removing ext_arr local match line_pos=1 int reg key all tmp_array input found input_line line_array line_val ext_var line_nr current_line match_key math removing ext_arr
local -a remove local -a remove
@ -1703,7 +1716,6 @@ create_graph_hires() { #? Create a graph from an array of percentage values, us
output_array=("${graph_array[@]}") output_array=("${graph_array[@]}")
} }
create_mini_graph_hires() { #? Create a one line high graph from an array of percentage values, usage; create_mini_graph <options> <value-array> create_mini_graph_hires() { #? Create a one line high graph from an array of percentage values, usage; create_mini_graph <options> <value-array>
#? Add a value to existing graph; create_mini_graph [-i, -invert] [-nc, -no-color] [-c, -color "array-name"] -add-value "graph_variable" <value> #? Add a value to existing graph; create_mini_graph [-i, -invert] [-nc, -no-color] [-c, -color "array-name"] -add-value "graph_variable" <value>
#? Add last value from an array to existing graph; create_mini_graph [-i, -invert] [-nc, -no-color] [-c, -color "array-name"] -add-last "graph_variable" "value-array" #? Add last value from an array to existing graph; create_mini_graph [-i, -invert] [-nc, -no-color] [-c, -color "array-name"] -add-last "graph_variable" "value-array"
@ -2171,7 +2183,7 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
mem[counter]=0 mem[counter]=0
local i tmp value array mem_info height=$((box[mem_height]-2)) skip filter_value local i tmp value array mem_info height=$((box[mem_height]-2)) skip filter_value
local -a mem_array gpu_array swap_array available=("mem") local -a mem_array swap_array available=("mem")
unset 'mem[total]' unset 'mem[total]'
#* Get memory and swap information from "/proc/meminfo" or psutil and calculate percentages #* Get memory and swap information from "/proc/meminfo" or psutil and calculate percentages
@ -2179,16 +2191,8 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
local pymemout local pymemout
py_command -v pymemout "get_mem()" || return py_command -v pymemout "get_mem()" || return
read mem[total] mem[free] mem[available] mem[cached] swap[total] swap[free] gpu[total] gpu[free] <<<"$pymemout" read mem[total] mem[free] mem[available] mem[cached] swap[total] swap[free] <<<"$pymemout"
if [[ $use_GPUtil == true ]]; then
if [[ -n ${gpu[total]} ]] && ((gpu[total]>0)); then
gpu[free_percent]=$((gpu[free]*100/gpu[total]))
gpu[used]=$((gpu[total]-gpu[free]))
gpu[used_percent]=$((gpu[used]*100/gpu[total]))
available+=("gpu")
fi
fi
if [[ -z ${mem[total]} ]]; then return; fi if [[ -z ${mem[total]} ]]; then return; fi
if [[ -n ${swap[total]} ]] && ((swap[total]>0)); then if [[ -n ${swap[total]} ]] && ((swap[total]>0)); then
swap[free_percent]=$((swap[free]*100/swap[total])) swap[free_percent]=$((swap[free]*100/swap[total]))
@ -2318,6 +2322,43 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
} }
collect_gpu() { #? Collect memory and usage information from GPUtil
if [[ $use_GPUtil == true ]]; then
local -a available=("gpu")
local pygpuout
py_command -v gpu[usage] "get_gpu_usage()"
py_command -v gpu[temp] "get_gpu_temp()"
py_command -v pygpuout "get_gpu_mem()" || return
read gpu[total] gpu[free] <<<"$pygpuout"
gpu[free_percent]=$((gpu[free]*100/gpu[total]))
gpu[used]=$((gpu[total]-gpu[free]))
gpu[used_percent]=$((gpu[used]*100/gpu[total]))
for array in ${available[@]}; do
for value in total used free available cached; do
if [[ $array == "gpu" && $value == "available" ]]; then break 2; fi
local -n this_value="${array}[${value}]" this_string="${array}[${value}_string]"
floating_humanizer -v this_string -s 1 -B "${this_value}"
done
done
local -n gpu_temp_history="gpu_temp_history"
if ((${#gpu_temp_history[@]}>40)); then
gpu_temp_history=( "${gpu_temp_history[@]:20}" "${gpu[temp]}")
else
gpu_temp_history+=("${gpu[temp]}")
fi
if ((${#gpu_history[@]}>tty_width*4)); then
gpu_history=( "${gpu_history[@]:$((tty_width*2))}" "$((gpu[usage]))")
else
gpu_history+=("$((gpu[usage]))")
fi
fi
}
collect_processes() { #? Collect process information and calculate accurate cpu usage collect_processes() { #? Collect process information and calculate accurate cpu usage
if [[ $use_psutil == true ]]; then collect_processes_psutil $1; return; fi if [[ $use_psutil == true ]]; then collect_processes_psutil $1; return; fi
local argument="$1" local argument="$1"
@ -2908,9 +2949,21 @@ calc_sizes() { #? Calculate width and height of all boxes
done done
#* Copy numbers around to get target layout #* Copy numbers around to get target layout
if [[ $use_GPUtil == true ]]; then
#* Make space for the gpu box if it is being used
box[gpu_line]=$((box[mem_line]))
box[gpu_col]=$((box[processes_col]))
box[gpu_height]=${box[net_height]}
box[gpu_width]=${box[processes_width]}
box[processes_line]=$((box[net_line]-$((box[mem_height]-box[gpu_height]))))
box[processes_height]=${box[mem_height]}
else
box[processes_line]=${box[mem_line]}
box[processes_height]=$((box[mem_height]+box[net_height]))
fi
box[mem_width]=${box[net_width]} box[mem_width]=${box[net_width]}
box[processes_line]=${box[mem_line]}
box[processes_height]=$((box[mem_height]+box[net_height]))
# threads=${box[testing]} #! For testing, remove <-------------- # threads=${box[testing]} #! For testing, remove <--------------
@ -2957,14 +3010,22 @@ calc_sizes() { #? Calculate width and height of all boxes
box[n_col]="$((net_width-box[n_width]+2))" box[n_col]="$((net_width-box[n_width]+2))"
box[n_line]="$((net_line+(net_height/2)-(box[n_height]/2)+1))" box[n_line]="$((net_line+(net_height/2)-(box[n_height]/2)+1))"
if [[ $use_GPUtil == true ]]; then
#* Calculate placement of gpu value box
local gpu_line=$((box[gpu_line]+1)) gpu_width=$((box[gpu_width]-2)) gpu_height=$((box[gpu_height]-2))
box[g_width]=32
box[g_height]=${gpu_height}
box[g_col]="$((gpu_width-box[g_width]+box[gpu_col]+2))"
box[g_line]="$((gpu_line+(gpu_height/2)-(box[g_height]/2)+1))"
fi
} }
draw_bg() { #? Draw all box outlines draw_bg() { #? Draw all box outlines
local this_box cpu_p_width i cpu_model_len local this_box cpu_p_width i cpu_model_len gpu_model_len gpu_driver_len
unset boxes_out unset boxes_out
for this_box in ${box[boxes]}; do for this_box in ${box[boxes]}; do
if [[ $this_box == "gpu" && $use_GPUtil == false ]]; then continue; fi
create_box -v boxes_out -col ${box[${this_box}_col]} -line ${box[${this_box}_line]} -width ${box[${this_box}_width]} -height ${box[${this_box}_height]} -fill -lc "${box[${this_box}_color]}" -title ${this_box} create_box -v boxes_out -col ${box[${this_box}_col]} -line ${box[${this_box}_line]} -width ${box[${this_box}_width]} -height ${box[${this_box}_height]} -fill -lc "${box[${this_box}_color]}" -title ${this_box}
done done
@ -2987,6 +3048,14 @@ draw_bg() { #? Draw all box outlines
create_box -v boxes_out -col $((box[n_col]-1)) -line $((box[n_line]-1)) -width ${box[n_width]} -height ${box[n_height]} -lc ${theme[div_line]} -t "Download" create_box -v boxes_out -col $((box[n_col]-1)) -line $((box[n_line]-1)) -width ${box[n_width]} -height ${box[n_height]} -lc ${theme[div_line]} -t "Download"
print -v boxes_out -m $((box[n_line]+box[n_height]-2)) $((box[n_col]+1)) -rs -fg ${theme[div_line]} -t "┤" -fg ${theme[title]} -b -t "Upload" -rs -fg ${theme[div_line]} -t "├" print -v boxes_out -m $((box[n_line]+box[n_height]-2)) $((box[n_col]+1)) -rs -fg ${theme[div_line]} -t "┤" -fg ${theme[title]} -b -t "Upload" -rs -fg ${theme[div_line]} -t "├"
#* Misc gpu box
if [[ $use_GPUtil == true ]]; then
gpu_model_len=${#gpu[model]}
gpu_driver_len=${#gpu[driver]}
create_box -v boxes_out -col $((box[g_col]-1)) -line $((box[g_line]-1)) -width ${box[g_width]} -height ${box[g_height]} -lc ${theme[div_line]} -t "${gpu[model]:0:${gpu_model_len}}"
print -v boxes_out -m $((box[g_line]+box[g_height]-2)) $((box[g_col]+1)) -rs -fg ${theme[div_line]} -t "┤" -fg ${theme[title]} -b -t "${gpu[driver]:0:${gpu_driver_len}}" -rs -fg ${theme[div_line]} -t "├"
fi
if [[ $1 == "quiet" ]]; then draw_out="${boxes_out}" if [[ $1 == "quiet" ]]; then draw_out="${boxes_out}"
else echo -en "${boxes_out}"; fi else echo -en "${boxes_out}"; fi
@ -3113,7 +3182,6 @@ draw_mem() { #? Draw mem, swap and disk statistics
local -a types=("mem") local -a types=("mem")
unset mem_out unset mem_out
if [[ $use_GPUtil == true && $use_psutil == true ]]; then types+=("gpu"); fi
if [[ -n ${swap[total]} && ${swap[total]} -gt 0 ]]; then types+=("swap"); fi if [[ -n ${swap[total]} && ${swap[total]} -gt 0 ]]; then types+=("swap"); fi
#* Get variables from previous calculations #* Get variables from previous calculations
@ -3127,8 +3195,6 @@ draw_mem() { #? Draw mem, swap and disk statistics
local -n type_name="$type" local -n type_name="$type"
if [[ $type == "mem" ]]; then if [[ $type == "mem" ]]; then
m_title="memory" m_title="memory"
elif [[ $type == "gpu" ]]; then
m_title="GPU Memory"
else else
m_title="$type" m_title="$type"
if ((height>14)); then ((y_pos++)); fi if ((height>14)); then ((y_pos++)); fi
@ -3139,7 +3205,6 @@ draw_mem() { #? Draw mem, swap and disk statistics
for value in ${values}; do for value in ${values}; do
if [[ $type == "swap" && $value =~ available|cached ]]; then continue; fi if [[ $type == "swap" && $value =~ available|cached ]]; then continue; fi
if [[ $type == "gpu" && $value =~ available|cached ]]; then continue; fi
if [[ $system == "MacOS" && $value == "cached" ]]; then value_text="active" if [[ $system == "MacOS" && $value == "cached" ]]; then value_text="active"
else value_text="${value::$((m_width-12))}"; fi else value_text="${value::$((m_width-12))}"; fi
@ -3231,6 +3296,71 @@ draw_mem() { #? Draw mem, swap and disk statistics
} }
draw_gpu() { #? Draw GPU usage, memory, and temperature graphs
if [[ $use_GPUtil == true ]]; then
local gpu_out
#* Get variables from previous calculations
local col=$((box[gpu_col]+1)) line=$((box[gpu_line]+1)) width=$((box[gpu_width]-2)) height=$((box[gpu_height]-2))
local g_width=${box[g_width]} g_height=${box[g_height]} g_col=${box[g_col]} g_line=${box[g_line]} main_fg="${theme[main_fg]}"
local graph_a_size graph_b_size
graph_a_size=$(( (height)/2 )); graph_b_size=${graph_a_size}
#* If resized recreate gpu box and gpu graphs
if ((resized>0)); then
local graph_a_size graph_b_size
graph_a_size=$(( (height)/2 )); graph_b_size=${graph_a_size}
if ((graph_a_size*2<height)); then ((graph_a_size++)); fi
gpu[graph_a_size]=$graph_a_size
gpu[graph_b_size]=$graph_b_size
gpu[download_redraw]=0
gpu[upload_redraw]=0
((resized++))
fi
#* I SWEAR I WILL MAKE THIS CLEANER SOON
#* Create graphs and meters for the gpu box
create_graph -o gpu_graph_a -d ${line} ${col} ${graph_a_size} $((width-p_width-box[g_width]-1)) -c color_gpu_graph -n gpu_history
create_graph -o gpu_graph_b -d $((line+graph_a_size)) ${col} ${graph_b_size} $((width-p_width-box[g_width]-1)) -c color_gpu_graph -i -n gpu_history
create_mini_graph -o "gpu_temp_graph" -w 10 -nc "gpu_temp_history"
gpu_temp_color="${color_gpu_graph[gpu[usage]]}"
core_name="cpu_core_1_graph"
meter="${!core_name}"
create_meter -v gpu_usage_meter -w $((box[g_width]-2)) -f -c color_gpu_graph $((gpu[usage]))
create_meter -v gpu_used_meter -w $((box[g_width]-6)) -f -c color_used_graph ${gpu[used_percent]}
create_meter -v gpu_free_meter -w $((box[g_width]-6)) -f -c color_free_graph ${gpu[free_percent]}
#* Humanize values that include memory
local ypos=$g_line
floating_humanizer -v gpu[total] -s 1 -B "${gpu[total]}"
floating_humanizer -v gpu[used] -s 1 -B "${gpu[used]}"
floating_humanizer -v gpu[free] -s 1 -B "${gpu[free]}"
#* Draw the labels, meters, and values in the gpu box
print -v gpu_out -rs -fg ${theme[title]} -b -m $((ypos++)) $g_col -jl 10 -t "GPU Usage:"\
-rs -fg ${main_fg} -jr 20 -t "$((gpu[usage]))%" -m $((ypos++)) $((box[g_col])) -t $gpu_usage_meter -rs -fg $normal_color
$((ypos++))
print -v gpu_out -rs -fg ${theme[title]} -b -m $((ypos++)) $g_col -jl 10 -t "GPU Memory:" -jr 19 -t "${gpu[total]}"
print -v gpu_out -rs -fg ${main_fg} -m $((ypos++)) $g_col -jl 10 -t "Used:" -jr 20 -t "${gpu[used]}"\
-m $((ypos++)) $((box[g_col])) -t $gpu_used_meter -rs -fg $normal_color -rs -fg ${main_fg} -jr 4 -t "${gpu[used_percent]}%"
print -v gpu_out -rs -fg ${main_fg} -m $((ypos++)) $g_col -jl 10 -t "Free:" -jr 20 -t "${gpu[free]}"\
-m $((ypos++)) $((box[g_col])) -t $gpu_free_meter -rs -fg $normal_color -rs -fg ${main_fg} -jr 4 -t "${gpu[free_percent]}%"
$((ypos++))
print -v gpu_out -m $((ypos++)) $g_col -rs -fg ${theme[main_fg]} -jl 14 -b -t "Temperature:" -rs -fg ${theme[inactive_fg]} "⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀" -l 10 -fg $gpu_temp_color -t "$meter"\
-jr 4 -fg $gpu_temp_color -t "${gpu[temp]}" -fg ${theme[main_fg]} -t "°C"
draw_out+="${gpu_graph_a[*]}${gpu_graph_b[*]}${gpu_graph_temp[*]}${gpu_out}"
fi
}
draw_processes() { #? Draw processes and values to screen draw_processes() { #? Draw processes and values to screen
local argument="$1" local argument="$1"
if [[ -n $skip_process_draw && $argument != "now" ]]; then return; fi if [[ -n $skip_process_draw && $argument != "now" ]]; then return; fi
@ -3870,12 +4000,12 @@ options_() { #? Shows the options overlay
"Can only be switched off when on Linux.") "Can only be switched off when on Linux.")
desc_use_GPUtil=( "Enable the use of GPUtil python3 module for" desc_use_GPUtil=( "Enable the use of GPUtil python3 module for"
"data collection. MAY NOT WORK ON SOME CARDS" "data collection. MAY NOT WORK ON SOME CARDS"
"(namely AMD cards)." "(namely AMD cards). psutil must be enabled."
"" ""
"Program will automatically restart when this" "Program will automatically restart when this"
"setting is changed to check for compatibility." "setting is changed to check for compatibility."
" " " "
"True or false. psutil must also be enabled." "True or false."
" " " "
"If incompatibility is detected the program will" "If incompatibility is detected the program will"
"automatically set this option to false upon" "automatically set this option to false upon"
@ -4651,7 +4781,7 @@ process_input() { #? Process keypresses for main ui
collect_and_draw() { #? Run all collect and draw functions collect_and_draw() { #? Run all collect and draw functions
local task_int=0 input_runs local task_int=0 input_runs
for task in processes cpu mem net; do for task in processes cpu mem net gpu; do
((++task_int)) ((++task_int))
if [[ -n $pause_screen && -n ${saved_key[0]} ]]; then if [[ -n $pause_screen && -n ${saved_key[0]} ]]; then
return return
@ -4902,7 +5032,12 @@ allowed_commands: Tuple[str] = (
'get_cmd_out', 'get_cmd_out',
'get_sensors', 'get_sensors',
'get_sensors_check', 'get_sensors_check',
'get_ms' 'get_ms',
'get_gpu_name',
'get_gpu_driver',
'get_gpu_mem',
'get_gpu_temp',
'get_gpu_usage'
) )
command: str = '' command: str = ''
cpu_count: int = psutil.cpu_count() cpu_count: int = psutil.cpu_count()
@ -5022,15 +5157,42 @@ def get_mem():
'''Get current system memory and swap usage''' '''Get current system memory and swap usage'''
mem = psutil.virtual_memory() mem = psutil.virtual_memory()
swap = psutil.swap_memory() swap = psutil.swap_memory()
'''GPU monitoring addition, will add some error checking later'''
gpu = GPUtil.getGPUs()[0]
gpu_total = int(gpu.memoryTotal)
gpu_free = int(gpu.memoryFree)
try: try:
cmem = mem.cached>>10 cmem = mem.cached>>10
except: except:
cmem = mem.active>>10 cmem = mem.active>>10
print(mem.total>>10, mem.free>>10, mem.available>>10, cmem, swap.total>>10, swap.free>>10, gpu_total<<10, gpu_free<<10) print(mem.total>>10, mem.free>>10, mem.available>>10, cmem, swap.total>>10, swap.free>>10)
def get_gpu_name():
'''Fetch GPU model name and chop it to fit in the box'''
gpu = GPUtil.getGPUs()[0]
name = ((gpu.name).split("GeForce ",1)[1])
print(name)
def get_gpu_driver():
'''Get current GPU driver'''
gpu = GPUtil.getGPUs()[0]
driver_name = ("Driver: {}".format(str(gpu.driver)))
print(driver_name)
def get_gpu_usage():
'''Get current GPU usage'''
gpu = GPUtil.getGPUs()[0]
load = int(gpu.load*100)
print(load)
def get_gpu_mem():
'''Get current GPU memory usage'''
gpu = GPUtil.getGPUs()[0]
gpu_total = int(gpu.memoryTotal)
gpu_free = int(gpu.memoryFree)
print(gpu_total<<10, gpu_free<<10)
def get_gpu_temp():
'''Get current GPU temperature'''
gpu = GPUtil.getGPUs()[0]
temp = int(gpu.temperature)
print(temp)
def get_nics(): def get_nics():
'''Get a list of all network devices sorted by highest throughput''' '''Get a list of all network devices sorted by highest throughput'''
@ -5279,6 +5441,7 @@ while command != 'quit':
continue continue
print('/EOL') print('/EOL')
#print(f'{command}', file=sys.stderr) #print(f'{command}', file=sys.stderr)
EOF EOF
fi fi
fi fi

View File

@ -1 +1,2 @@
psutil==5.7.0 psutil==5.7.0
GPUtil==1.4.0

View File

@ -33,7 +33,12 @@ allowed_commands: Tuple[str] = (
'get_cmd_out', 'get_cmd_out',
'get_sensors', 'get_sensors',
'get_sensors_check', 'get_sensors_check',
'get_ms' 'get_ms',
'get_gpu_name',
'get_gpu_driver',
'get_gpu_mem',
'get_gpu_temp',
'get_gpu_usage'
) )
command: str = '' command: str = ''
cpu_count: int = psutil.cpu_count() cpu_count: int = psutil.cpu_count()
@ -153,15 +158,42 @@ def get_mem():
'''Get current system memory and swap usage''' '''Get current system memory and swap usage'''
mem = psutil.virtual_memory() mem = psutil.virtual_memory()
swap = psutil.swap_memory() swap = psutil.swap_memory()
'''GPU monitoring addition, will add some error checking later'''
gpu = GPUtil.getGPUs()[0]
gpu_total = int(gpu.memoryTotal)
gpu_free = int(gpu.memoryFree)
try: try:
cmem = mem.cached>>10 cmem = mem.cached>>10
except: except:
cmem = mem.active>>10 cmem = mem.active>>10
print(mem.total>>10, mem.free>>10, mem.available>>10, cmem, swap.total>>10, swap.free>>10, gpu_total<<10, gpu_free<<10) print(mem.total>>10, mem.free>>10, mem.available>>10, cmem, swap.total>>10, swap.free>>10)
def get_gpu_name():
'''Fetch GPU model name and chop it to fit in the box'''
gpu = GPUtil.getGPUs()[0]
name = ((gpu.name).split("GeForce ",1)[1])
print(name)
def get_gpu_driver():
'''Get current GPU driver'''
gpu = GPUtil.getGPUs()[0]
driver_name = ("Driver: {}".format(str(gpu.driver)))
print(driver_name)
def get_gpu_usage():
'''Get current GPU usage'''
gpu = GPUtil.getGPUs()[0]
load = int(gpu.load*100)
print(load)
def get_gpu_mem():
'''Get current GPU memory usage'''
gpu = GPUtil.getGPUs()[0]
gpu_total = int(gpu.memoryTotal)
gpu_free = int(gpu.memoryFree)
print(gpu_total<<10, gpu_free<<10)
def get_gpu_temp():
'''Get current GPU temperature'''
gpu = GPUtil.getGPUs()[0]
temp = int(gpu.temperature)
print(temp)
def get_nics(): def get_nics():
'''Get a list of all network devices sorted by highest throughput''' '''Get a list of all network devices sorted by highest throughput'''