diff options
Diffstat (limited to 'core/modules/hardware-stats/data/opt/openslx/scripts')
-rwxr-xr-x | core/modules/hardware-stats/data/opt/openslx/scripts/systemd-gather_hw_info | 36 | ||||
-rwxr-xr-x | core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report | 17 |
2 files changed, 25 insertions, 28 deletions
diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-gather_hw_info b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-gather_hw_info index cdeb6d63..545cb4bc 100755 --- a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-gather_hw_info +++ b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-gather_hw_info @@ -9,8 +9,8 @@ export LANG=C.UTF-8 export LC_ALL=C.UTF-8 -declare -rg REPORTFILE="/run/hwreport" -declare -rg jsonfile="/run/hwreport.json" +declare -rg REPORTFILE="/run/openslx/hwreport" +declare -rg jsonfile="/run/openslx/hwreport.json" # new json-based reporting, run first in background and wait at the end of script # This is only supported by Sat3.11, released 12-2023, so keep creating the old format @@ -60,7 +60,7 @@ slxfdisk() { MAC="${SLX_PXE_MAC}" if [ -z "$MAC" ]; then # get MAC from sysfs - MAC="$(cat /sys/class/net/${SLX_PXE_NETIF:-br0}/address)" + MAC="$( cat "/sys/class/net/${SLX_PXE_NETIF:-br0}/address" )" fi if [ -z "$MAC" ]; then BOOTIF="$(grep -Po '(?<=BOOTIF=)[0-9a-f\-:]+' /proc/cmdline)" @@ -89,7 +89,7 @@ CPUSOCKETS=$(grep '^physical id' /proc/cpuinfo | sort -u | wc -l) # Fallback 1... if [ -z "$CPUCORES" ] || [ "$CPUCORES" = "0" ]; then for c in $(dmidecode -t 4 | grep 'Core Enabled' | awk -F ':' '{print $2}'); do - CPUCORES=$(( $CPUCORES + $c )) + CPUCORES=$(( CPUCORES + c )) done fi # Fallback 2... @@ -108,12 +108,12 @@ echo "$CPUMODEL" # 4) RAM # RAM=$(grep -m1 '^MemTotal:' /proc/meminfo | awk '{print $2}') -RAM=$(( $RAM / 1024 )) +RAM=$(( RAM / 1024 )) if [ -z "$RAM" ] || [ "$RAM" -lt 500 ]; then # Fallback to dmidecode RAM=0 for c in $(dmidecode -t 17 | grep -o 'Size:.*MB$' | awk '{print $2}'); do - RAM=$(( $RAM + $c )) + RAM=$(( RAM + c )) done fi echo "$RAM MB RAM" @@ -173,7 +173,7 @@ if ! slx-tools fs_path_isvolatile "/tmp/virt" ; then [ "$val" -gt "$ID44" ] && ID44=$val done # blockdev reports bytes, convert to MB - ID44=$(( $ID44 / 1058576 )) # we'd rather underreport + ID44=$(( ID44 / 1058576 )) # we'd rather underreport fi fi fi @@ -183,13 +183,15 @@ echo "Scratch space: $ID44 MB" # 7) check smart values # FDISK=$(mktemp) -declare -a DISKS +declare -A DISKS shopt -s extglob for disk in /dev/disk/by-path/!(*-part*|*-usb-*); do [ -L "$disk" ] || continue + [ -z "${DISKS["$disk"]}" ] || continue disk="$( readlink -f "$disk" )" - DISKS+=("$disk") - slxfdisk -l "$disk" | sed -r 's/\s+[0-9]+,[0-9]+,[0-9]+/ /g;/^\// s/\s[0-9]+\.?[0-9]+[MGT]\s/ /;s/^Units: /Units =foo= /' | awk '{if ($1 !~ /^[0-9]+$/ || $5 ~ /^[0-9a-f]{4}/) { print $0 } else { $5 = "0700 " $5; print $0 }}' # Work around busybox YET AGAIN changing something in an incompatible way + DISKS["$disk"]="$disk" + slxfdisk -l "$disk" | sed -r 's/\s+[0-9]+,[0-9]+,[0-9]+/ /g;/^\// s/\s[0-9]+\.?[0-9]+[MGT]\s/ /;s/^Units: /Units =foo= /' \ + | awk '{if ($1 !~ /^[0-9]+$/ || $5 ~ /^[0-9a-f]{4}/) { print $0 } else { $5 = "0700 " $5; print $0 }}' # Work around busybox YET AGAIN changing something in an incompatible way done > "$FDISK" shopt -u extglob [ -z "$SLX_SMARTCTL_MIN_REALLOC" ] && SLX_SMARTCTL_MIN_REALLOC=0 @@ -207,20 +209,20 @@ if which smartctl; then cat "$FILE" >> "$ALLSMART" # parse OVERALL=$(grep -o "test result: .*$" "$FILE" | cut -c 14-) - [ "x$OVERALL" = "xPASSED" ] && OVERALL="" + [ "$OVERALL" = "PASSED" ] && OVERALL="" REALLOC=$(grep "^ *5 " "$FILE" | awk '{print $8}') PENDING=$(grep "^ *197 " "$FILE" | awk '{print $8}') SPINRETRY_VAL=$(grep "^ *10 " "$FILE" | awk '{print $4}') SPINRETRY_THR=$(grep "^ *10 " "$FILE" | awk '{print $6}') - [ -n "$OVERALL" ] && BADSECTORS=$(( $BADSECTORS + 100 )) + [ -n "$OVERALL" ] && BADSECTORS=$(( BADSECTORS + 100 )) if [ -n "$REALLOC" ] && [ "$REALLOC" -gt "0" ]; then - BADSECTORS=$(( $BADSECTORS + $REALLOC )) + BADSECTORS=$(( BADSECTORS + REALLOC )) fi if [ -n "$PENDING" ] && [ "$PENDING" -gt "5" ]; then - BADSECTORS=$(( $BADSECTORS + $PENDING )) + BADSECTORS=$(( BADSECTORS + PENDING )) fi if [ -n "$SPINRETRY_VAL" ] && [ "$SPINRETRY_VAL" -le "$SPINRETRY_THR" ]; then - BADSECTORS=$(( $BADSECTORS + 100 )) + BADSECTORS=$(( BADSECTORS + 100 )) fi done rm -f -- "$FILE" @@ -231,7 +233,7 @@ echo "SMART: $OVERALL - $REALLOC reallocated, $PENDING pending" # 8) Read system model and manufacturer # dmidec() { - local RETVAL=$(dmidecode "$@" 2>/dev/null | grep -v '^#' | grep -v '^Invalid' | sed 's/\s\s*/ /g;s/^ //;s/ $//') + local RETVAL=$( dmidecode "$@" 2>/dev/null | grep -v '^#' | grep -v '^Invalid' | sed 's/\s\s*/ /g;s/^ //;s/ $//' ) case "$RETVAL" in ""|*"Product Name"*|*"be filled"*|"unknown"|*"efault string"*|*"efault String"*|*"product name"*|*"anufacturer"*|*"ystem model"*) RETVAL="Unknown" @@ -290,7 +292,7 @@ echo "Created report file" ################################################################################ # Save information to local file for later use # -cat > "/run/hwinfo" <<HORST +cat > "/run/openslx/hwinfo" <<HORST HW_KVM='${VT}' HW_ID44='${ID44}' HW_MAC='${MAC}' diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report index 64d0f090..bf1fe6ee 100755 --- a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report +++ b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report @@ -8,23 +8,21 @@ disable_remote_logging() { } # sends the hardware information of this machine generated by -# systemd-hardware_stats_gather in /run/hwreport and /run/hwinfo +# systemd-hardware_stats_gather in /run/openslx/hwreport and /run/openslx/hwinfo report_hardware_info() { local uptime hwreport hwinfo uuid model subnet ret runmode jsonfile if [ -z "$SLX_REMOTE_LOG" ]; then disable_remote_logging return 1 fi - hwreport="/run/hwreport" - jsonfile="/run/hwreport.json" + hwreport="/run/openslx/hwreport" + jsonfile="/run/openslx/hwreport.json" if ! [ -s "$hwreport" ] && ! [ -s "$jsonfile" ]; then echo "Missing hwreport file: $hwreport AND $jsonfile" - # TODO send data without? - return 1 fi # Read generated data and current uptime and send it - hwinfo="/run/hwinfo" + hwinfo="/run/openslx/hwinfo" if [ ! -s "$hwinfo" ]; then echo "Missing hwinfo file: $hwinfo" return 1 @@ -80,8 +78,8 @@ report_hardware_info() { fi echo "succeeded." rm -f -- "$hwreport" "$jsonfile" - START=$(( $RANDOM % 5 )) - DELAY=$(( $RANDOM % 20 )) + START=$(( RANDOM % 5 )) + DELAY=$(( RANDOM % 20 )) # Do not move/rename this file, we check its existence in other scripts cat > "/etc/cron.d/usage_stats" <<-EOF # Update usage statistics on server @@ -90,9 +88,6 @@ report_hardware_info() { ${START}-59/5 * * * * root sleep ${DELAY}; /opt/openslx/scripts/cron-system_usage_update --full EOF - # TODO remove this hack one day: Sometimes, aufs doesn't update the mtime of dirs - # when creating files, so cron would not rescan the cron directory. - touch "/etc/cron.d" # Trigger right now so resource usage gets updated /opt/openslx/scripts/cron-system_usage_update --full return 0 |