Code Done Right!

Basic data collection

The below script will allow for basic data collection. You can set up a crontab (see here) so that it runs every five minutes and updates a file, from which you can copy the data to Excel or Libre Offiec Calc to create a chart showing overall performance.

The data collection script gathers the following information
  • Date
  • Time
  • CPU temperature
  • RAM usage
  • Average 5 minute load
Data collection script code


date="$(which date)"
timestamp=`$date '+%Y-%m-%d %H:%M'`

cur_temp=$(cat /sys/class/thermal/thermal_zone0/temp)
cur_temp="$(echo "$cur_temp / 1000" | bc -l | xargs printf "%1.0f")"

ram_used="$(free -t -m | grep "Mem" | awk '{print $3}')"

read -r loadavg_five rest < /proc/loadavg

echo "$timestamp ; $cur_temp ; $ram_used ; $loadavg_five" 1>> $data_output

If you did not figure out from the script itself, you will find all your data neatly arranged in the following location


AFTER you run the script for the first time, check if the data is actually being written to the file with the following command

cat /var/zzz_log/performance.log

You should see output similar to this

2020-02-05 20:32 ; 41 ; 251 ; 0.00

Now, once you gain enough data go ahead and construct your chart to showcase performance of your server!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.