From 687be54de1ca5c7c5aa566c8becb8e3ff707c5e6 Mon Sep 17 00:00:00 2001 From: Stephan Wendel Date: Sun, 12 Jun 2022 18:55:51 +0200 Subject: [PATCH] feat(logging): display host information in log file Adds Information Distribution,Release,Kernel,Host model,Cpu Count, Total Ram and Diskusage to log, if not set to log_level: quiet Signed-off-by: Stephan Wendel --- libs/logging.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libs/logging.sh b/libs/logging.sh index 0d72058..30d390b 100755 --- a/libs/logging.sh +++ b/libs/logging.sh @@ -33,6 +33,7 @@ function init_logging { log_msg "crowsnest - A webcam Service for multiple Cams and Stream Services." log_msg "Version: $(self_version)" log_msg "Prepare Startup ..." + print_host } function log_level { @@ -116,6 +117,44 @@ function print_cams { fi } +function print_host { + local disksize generic_model memtotal sbc_model + generic_model="$(grep "model name" /proc/cpuinfo | cut -d':' -f2)" + sbc_model="$(grep "Model" /proc/cpuinfo | cut -d':' -f2)" + memtotal="$(grep "MemTotal:" /proc/meminfo | awk '{print $2" "$3}')" + disksize="$(LC_ALL=C df -h / | awk 'NR==2 {print $4" / "$2}')" + ## print only if not log_level: quiet + if [ "$(log_level)" != "quiet" ]; then + log_msg "INFO: Host information:" + ## OS Infos + ## OS Version + if [ -f /etc/os-release ]; then + log_msg "Host Info: Distribution: $(grep "PRETTY" /etc/os-release | \ + cut -d '=' -f2 | sed 's/^"//;s/"$//')" + fi + ## Release Version of MainsailOS (if file present) + if [ -f /etc/mainsailos-release ]; then + log_msg "Host Info: Release: $(cat /etc/mainsailos-release)" + fi + ## Kernel version + log_msg "Host Info: Kernel: $(uname -s) $(uname -rm)" + ## Host Machine Infos + ## Host model + if [ -n "${sbc_model}" ]; then + log_msg "Host Info: Model: ${sbc_model}" + fi + if [ -n "${generic_model}" ]; then + log_msg "Host Info: Model: ${generic_model}" + fi + ## CPU count + log_msg "Host Info: Available CPU Cores: $(nproc)" + ## Avail mem + log_msg "Host Info: Available Memory: ${memtotal}" + ## Avail disk size + log_msg "Host Info: Diskspace (used / total): ${disksize}" + fi +} + function debug_msg { local prefix prefix="Develop -- DEBUG:"