From 9dc8ddb39b7cf8fbd3b857ddac06a7a653f28202 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 24 Oct 2016 16:17:38 +0200 Subject: [hardware-stats] Write more stuff to /run/hwinfo Added virtual cpu core count, system model, system manufacturer --- .../opt/openslx/scripts/systemd-hardware_stats | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats index 5a776054..6f4e25ec 100755 --- a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats +++ b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats @@ -49,7 +49,10 @@ fi # 3) Uptime in seconds UPTIME=$(grep -o -E '^[0-9]+' /proc/uptime) -# 4) Number of real CPU cores +# 4) Number of real and virtual CPU cores +# Virtual, cheap way +VCORES=$(grep '^processor\s' /proc/cpuinfo | sort -u | wc -l) +# Real cores CPUCORES=$(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -u | wc -l) # Fallback 1... if [ -z "$CPUCORES" ] || [ "$CPUCORES" = "0" ]; then @@ -143,24 +146,26 @@ fi # A) Read system model and manufacturer dmidec() { - local LMODEL=$(dmidecode "$@" 2>/dev/null | grep -v '^#' | grep -v '^Invalid' | sed 's/\s\s*/ /g;s/^ //;s/ $//') - case "$LMODEL" in + 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"|*"product name"*) - LMODEL="Unknown" + RETVAL="Unknown" ;; esac - echo "$LMODEL" + echo "$RETVAL" } -MODEL=$(dmidec -q -s system-product-name) -MANUF=$(dmidec -q -s system-manufacturer) + +HW_MODEL=$(dmidec -q -s system-product-name) +HW_MANUF=$(dmidec -q -s system-manufacturer) # Try fallback to baseboard -if [ "$MODEL" = "Unknown" ]; then - MODEL=$(dmidec -q -s baseboard-product-name) - MANUF=$(dmidec -q -s baseboard-manufacturer) +if [ "$HW_MODEL" = "Unknown" ]; then + HW_MODEL=$(dmidec -q -s baseboard-product-name) + HW_MANUF=$(dmidec -q -s baseboard-manufacturer) fi -if [ "$MANUF" != "Unknown" ]; then - MODEL="$MODEL ($MANUF)" +MODEL="$HW_MODEL" +if [ "$HW_MANUF" != "Unknown" ]; then + MODEL="$MODEL ($HW_MANUF)" fi # n) Dump raw data to a file @@ -169,7 +174,7 @@ cat > "$DATAFILE" <<-EOF ############################### CPU ##################################### Sockets: $(grep '^physical id' /proc/cpuinfo | sort -u | wc -l) Real cores: $CPUCORES -Virtual cores: $(grep '^processor' /proc/cpuinfo | sort -u | wc -l) +Virtual cores: $VCORES ######################## Partition tables ############################### EOF cat "$FDISK" >> "$DATAFILE" @@ -198,11 +203,20 @@ HDDCOUNT=0 for size in $(cat "$FDISK" | grep -E '^Disk /dev.*[0-9]{11,} bytes' | grep -o -E '[0-9]{11,}'); do [ "$size" -gt 50000000000 ] && HDDCOUNT=$(( HDDCOUNT + 1 )) done +bashesc () { + sed s/\'/\'\"\'\"\'/g <<<$* +} +HW_MANUF=$(bashesc "$HW_MANUF") +HW_MODEL=$(bashesc "$HW_MODEL") cat > "/run/hwinfo" <