Retrieve the Linux System Environment

Given that this project includes benchmarking different configurations, it would be useful to have a script which explores and reports on the system configuration.  We can then run this script prior to the benchmark to ensure that we have an accurate record of the system we are testing.

Most of this information is freely available in the /proc directory which is present on all Linux systems.   It is a virtual file system, including files such as meminfo, cpuinfo and numbered directories representing processes.  In any process directory you can explore the status, io, etc. using cat <filename>.

/proc/cmdline – Kernel command line information.
/proc/console – Information about current consoles including tty.
/proc/devices – Device drivers currently configured for the running kernel.
/proc/dma – Info about current DMA channels.
/proc/fb – Framebuffer devices.
/proc/filesystems – Current filesystems supported by the kernel.
/proc/iomem – Current system memory map for devices.
/proc/ioports – Registered port regions for input output communication with device.
/proc/loadavg – System load average.
/proc/locks – Files currently locked by kernel.
/proc/meminfo – Info about system memory (see above example).
/proc/misc – Miscellaneous drivers registered for miscellaneous major device.
/proc/modules – Currently loaded kernel modules.
/proc/mounts – List of all mounts in use by system.
/proc/partitions – Detailed info about partitions available to the system.
/proc/pci – Information about every PCI device.
/proc/stat – Record or various statistics kept from last reboot.
/proc/swap – Information about swap space.
/proc/uptime – Uptime information (in seconds).
/proc/version – Kernel version, gcc version, and Linux distribution installed.

http://www.unix-consultants.co.uk/examples/scripts/linux/linux-explorer/  – rather too heavy and it takes forever to run on the pi.  A good place for ideas.

We could use python instead of bash, might be easier to integrate, depending on what comes next, uses the python platform module http://echorand.me/site/notes/articles/python_linux/article.html

We could implement a bash script which could monitor system performance for a given time, save the output to a log file and then analyse the data afterwards.  Initially considering recording memory, disk and cpu usage, I’ve implemented this script and found that the values reported for CPU usage do not match the raspberry pi cpu usage monitor displayed on the panel.  http://www.systeen.com/2016/05/07/bash-script-monitor-cpu-memory-disk-usage-linux/

# memory - display the free and used memory in megabytes
# using awk extract the data from the second line
free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2}' 

# execute top for 1 iteration
# grep the line containing load
# use awk to extract the second last entry on the line
top -bn1 | grep load | awk '{printf "%.2f%%\t\t", $(NF-2)}'

# disk file usage in human readable format
#using awk extract the 5th field from the line containing /
df -h | awk '$NF=="/"{printf "%s\t\t, $5}'

Wrap this with a while loop to take readings at specific time intervals.

#!/bin/bash
printf "memory\t\tdisk\t\tcpu\t"
end=$((SECONDS+3600))
while [ $SECONDS -lt $end ]; do
MEMORY=$(free -m|awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2}')
DISK=$df -h|awk '$NF=="/"{printf"%s\t\t", $5}')
CPU=$top -bn1|grep load|awk '{printf "%.2f%%\t\n", $(NF-2)}')
echo "$MEMORY$DISK$CPU"
sleep 5
done

Run the script file, then put the memory / disk / cpu under stress.

sysbench --test=cpu --cpu-max-prime=20000 run
stress --cpu 20 --io 20 --vm 6 --vm-bytes 25M --timeout 50s

http://www.unix-consultants.co.uk/examples/scripts/linux/linux-explorer/  – rather too heavy and it takes forever to run on the pi.  A good place for ideas.

We could use python instead of bash, might be easier to integrate, depending on what comes next, uses the python platform module:  http://echorand.me/site/notes/articles/python_linux/article.html

https://help.ubuntu.com/community/Beginners/BashScripting 

http://unix.stackexchange.com/questions/69167/bash-script-that-print-cpu-usage-diskusage-ram-usage 

Leave a Reply

Your email address will not be published. Required fields are marked *