From 5cd6616479bb9af5d836a6f995120594800049df Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Feb 2023 17:25:03 +0000 Subject: [PATCH] add OpenBSD --- scripts/cpu_info.sh | 10 +++++++++- scripts/ram_info.sh | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 41b49c1..9a33900 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -21,6 +21,14 @@ get_percent() normalize_percent_len $percent ;; + OpenBSD) + cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}') + cpucores=$(sysctl -n hw.ncpuonline) + cpuusage=$(( cpuvalue / cpucores )) + percent="$cpuusage%" + normalize_percent_len $percent + ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) # TODO - windows compatability ;; @@ -29,7 +37,7 @@ get_percent() get_load() { case $(uname -s) in - Linux | Darwin) + Linux | Darwin | OpenBSD) loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g') echo $loadavg ;; diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 97d61b6..412f0b8 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -56,6 +56,22 @@ get_percent() fi ;; + OpenBSD) + # vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p' + # Looked at the code from neofetch + hw_pagesize="$(pagesize)" + free_mem=$(($(vmstat -s | grep "pages free$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') * hw_pagesize / 1024 / 1024 )) + total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) + used_mem=$((total_mem - free_mem)) + total_mem=$(($total_mem/1024)) + if (( $used_mem < 1024 )); then + echo $used_mem\M\B/$total_mem\G\B + else + memory=$(($used_mem/1024)) + echo $memory\G\B/$total_mem\G\B + fi + ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) # TODO - windows compatability ;;