diff --git a/tests/p_sysstat/0-install_sysstat.sh b/tests/p_sysstat/0-install_sysstat.sh deleted file mode 100755 index 918a269..0000000 --- a/tests/p_sysstat/0-install_sysstat.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Author: Steve Barnes (steve@echo.id.au) - -# SysStat Performance Monitoring Tools for Linux -t_InstallPackage sysstat diff --git a/tests/p_sysstat/00-install_sysstat.sh b/tests/p_sysstat/00-install_sysstat.sh new file mode 100755 index 0000000..3da2a5f --- /dev/null +++ b/tests/p_sysstat/00-install_sysstat.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) + +# SysStat Performance Monitoring Tools for Linux +t_InstallPackage sysstat + +if [ "$centos_ver" -lt 8 ] ; then + t_InstallPackage psmisc +fi + + diff --git a/tests/p_sysstat/05-iostat-cpu-basic.sh b/tests/p_sysstat/05-iostat-cpu-basic.sh index c085fb8..bcf8cf6 100755 --- a/tests/p_sysstat/05-iostat-cpu-basic.sh +++ b/tests/p_sysstat/05-iostat-cpu-basic.sh @@ -5,34 +5,37 @@ t_Log "Running $0 - a basic iostat test to verify cpu measurement" -# Save our iostat output somewhere -TMP=/tmp/iostat.cpu.scratch +# Save our iostat output +output_file=$(mktemp) +trap "rm -f ${output_file}" EXIT # Clear out the pagecache to get an accurate reading echo 1 > /proc/sys/vm/drop_caches -# Clean up after ourselves -trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT - # Capture a storage device name -DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') +drive=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') # Run iostat on the cpu -/usr/bin/iostat -c 1 5 >$TMP & +/usr/bin/iostat -c 1 5 >${output_file} 2>&1 & -# Let the dust settle -sleep 4 +# Time for iostat booting +sleep 1 # Give the CPU something to chew on -/bin/dd if=$DRIVE bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null +/bin/dd if=$drive bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null # Give iostat a chance to log our task sleep 6 # Extract the CPU utilisation (user field, percentage) -CPU_USER_PCENT=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' $TMP) +cpu_user_percent=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' ${output_file}) # Confirm the CPU registered some level of user activity -[ "$CPU_USER_PCENT" -gt 3 ] || { t_Log "iostat didn't log any CPU activity?!...that ain't good"; } -t_CheckExitStatus $? +if [ "$cpu_user_percent" -eq 0 ]; then + t_Log "FAIL: ${0}: no cpu activity registered" + cat ${output_file} + t_CheckExitStatus 1 +fi + +t_CheckExitStatus 0 diff --git a/tests/p_sysstat/10-iostat-disk-basic.sh b/tests/p_sysstat/10-iostat-disk-basic.sh index a29a36c..6146e62 100755 --- a/tests/p_sysstat/10-iostat-disk-basic.sh +++ b/tests/p_sysstat/10-iostat-disk-basic.sh @@ -5,40 +5,41 @@ t_Log "Running $0 - a basic iostat test to verify disk measurement" -# Save our iostat output somewhere -TMP=/tmp/iostat.disk.scratch +output_file=$(mktemp) +trap "rm -f ${output_file}" EXIT # dd options -BS=4196 -COUNT=10100 -SUM=$(expr $BS \* $COUNT / 1024) +bs=4196 +count=10100 +sum=$(expr $bs \* $count / 1024) -# Clean up after ourselves -trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT # Clear out the pagecache to get an accurate reading echo 1 > /proc/sys/vm/drop_caches # Capture a storage device name -DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') +drive=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') # Run iostat on the device -/usr/bin/iostat -dkx 1 5 $DRIVE >$TMP & +/usr/bin/iostat -d 1 5 $drive >${output_file} 2>&1 & -# Let the dust settle -sleep 4 +# Time for iostat booting +sleep 1 # Generate some read traffic -/bin/dd if=$DRIVE of=/dev/null bs=$BS count=$COUNT &>/dev/null +/bin/dd if=$drive of=/dev/null bs=$bs count=$count &>/dev/null # Give iostat a chance to log our traffic sleep 6 # Confirm our read bytes are >0, excluding the first # line since that's the average since boot. -BYTES_READ=$(awk '$6 ~ /[0-9]/ {NR>1 && sum+=$6} END {print int(sum)}' $TMP) +kbytes_read=$(awk '$6 ~ /[0-9]/ {NR>1 && sum+=$6} END {print int(sum)}' ${output_file}) -# Check we read at least as much as requested -[ "$BYTES_READ" -ge "$SUM" ] || { t_Log "iostat didn't log as much traffic as we generated?!...that ain't good"; } +if [ "$kbytes_read" -eq 0 ]; then + t_Log "FAIL: ${0}: no io activity registered" + cat ${output_file} + t_CheckExitStatus 1 +fi -t_CheckExitStatus $? +t_CheckExitStatus 0 diff --git a/tests/p_sysstat/15-mpstat-basic.sh b/tests/p_sysstat/15-mpstat-basic.sh index 78a1bb6..bedcaaa 100755 --- a/tests/p_sysstat/15-mpstat-basic.sh +++ b/tests/p_sysstat/15-mpstat-basic.sh @@ -5,29 +5,36 @@ t_Log "Running $0 - a simple mpstat test to verify cpu load is being measured" -# Save our iostat output somewhere -TMP=/tmp/mpstat.scratch +output_file=$(mktemp) +trap "rm -f ${output_file}" EXIT -# Clean up after ourselves -trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT +n_cpu=$(nproc) +load=$((${n_cpu}/2)) +if [ "${load}" -eq 0 ]; then + load=1 +fi -# Run iostat on the first CPU -/usr/bin/mpstat -P 0 1 5 >$TMP & +/usr/bin/mpstat 1 5 >${output_file} 2>&1 & -# Let the dust settle -sleep 4 +# Time for iostat booting +sleep 1 # Give the CPU something to chew on -/bin/dd if=/dev/urandom bs=1k count=10000 2>/dev/null|sha1sum -b - &>/dev/null +for i in $(seq 1 ${load}); do + sha1sum /dev/zero & +done # Give mpstat a chance to log our task sleep 6 -# Confirm our read bytes are >0, excluding the first -# line since that's the average since boot. -CPU_SYS_PCENT=$(awk '$6 ~ /[0-9]\./ {$6>a ? a=$6 : $6} END {print int(a)}' $TMP) +killall sha1sum -# Check mpstat registered some level of cpu activity -[ "$CPU_SYS_PCENT" -gt 5 ] || { t_Log "mpstat didn't log any CPU activity?!...that ain't good"; } +cpu_user_percent=$(awk '$4 ~ /[0-9]\./ {$4>a ? a=$4 : $4} END {print int(a)}' ${output_file}) -t_CheckExitStatus $? +if [ "$cpu_user_percent" -eq 0 ]; then + t_Log "FAIL: ${0}: no cpu activity registered" + cat ${output_file} + t_CheckExitStatus 1 +fi + +t_CheckExitStatus 0