RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. RRDtool can be easily integrated in shell scripts, perl, python, ruby, lua or tcl applications.
more info:
RRDtool refers to Round Robin Database tool. Round robin is a technique that works with a fixed amount of data, and a pointer to the current element. Think of a circle with some dots plotted on the edge. These dots are the places where data can be stored. Draw an arrow from the center of the circle to one of the dots; this is the pointer. When the current data is read or written, the pointer moves to the next element. As we are on a circle there is neither a beginning nor an end, you can go on and on and on. After a while, all the available places will be used and the process automatically reuses old locations. This way, the dataset will not grow in size and therefore requires no maintenance. RRDtool works with Round Robin Databases (RRDs). It stores and retrieves data from them.
Install
sudo apt install rrdtool
rrdtool create database2.rrd --start -1h \
--step 10 \
--no-overwrite \
DS:num:GAUGE:30:0:100 \
RRA:AVERAGE:0.5:5:9500
explanation:
param | description |
---|---|
--step 10 | I want to collect updates every 10 seconds |
--no-overwrite | No action takes place if the database already exists |
DS:num:GAUGE:30:0:100 | Create a dataset num with values between 0 and 100. If no data comes during heartbeat 30 sec store UNDEFINED |
RRA:AVERAGE:0.5:5:9500 | Calculates and stores 9500 records and store the AVERAGE in case multiple values are supplied during the same interval (step 10 seconds). |
- Create 9500 items long
- round-robin archive (RRA)
- where every item is an AVERAGE
- of 5 data points from the data source.
- If more than half (>0.5) of those 5 are UNDEFINED, assume aggregated value UNDEFINED as well.
or: (https://codeblog.dotsandbrackets.com/quick-intro-to-rrdtool/)
#!/bin/bash
#################### start.sh ####################
while true
do
temp=$(sensors | grep "Core 0" | awk '{print $3}' | cut -c "2-5")
rrdtool update database2.rrd N:$temp
echo $temp
sleep 5
done
- script runs infinitely and every 5 seconds it updates DB
-
Infinitely:
stress-ng --cpu 4 --cpu-method matrixprod --metrics-brief --perf
-
With timeout 60 min:
stress-ng --cpu 4 --cpu-method matrixprod --metrics-brief --perf --timeout 3600s
#!/bin/bash
#################### plot.sh ####################
rrdtool graph ./graph5.png \
--start -1h \
--title "CPU Temperature" \
--vertical-label "Temperature (ยฐC)" \
-w 900 -h 400 \
DEF:temp=./database2.rrd:num:AVERAGE \
LINE1:temp#FF0000:"CPU Temperature"
-
To see updated graph every 10 seconds:
watch -n 10 ./plot.sh
You will get something like this:
another example with bigger time window and resolution:
-
Graph shows 3,5 hod full load of CPU Intel G3220T in fully passive (fanless) PC, limited to 25W in BIOS
- ambient temperature in room was 23โpc@pc-exone:~/cputmp$ neofetch .-/+oossssoo+/-. pc@pc-exone `:+ssssssssssssssssss+:` ----------- -+ssssssssssssssssssyyssss+- OS: Ubuntu 23.10 x86_64 .ossssssssssssssssssdMMMNysssso. Kernel: 6.5.0-10-generic /ssssssssssshdmmNNmmyNMMMMhssssss/ Uptime: 3 mins +ssssssssshmydMMMMMMMNddddyssssssss+ Packages: 1926 (dpkg), 11 (flatpak) /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Shell: bash 5.2.15 .ssssssssdMMMNhsssssssssshNMMMdssssssss. Resolution: 1920x1080 +sssshhhyNMMNyssssssssssssyNMMMysssssss+ DE: GNOME 45.0 ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM: Mutter ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM Theme: Adwaita +sssshhhyNMMNyssssssssssssyNMMMysssssss+ Theme: Yaru-dark [GTK2/3] .ssssssssdMMMNhsssssssssshNMMMdssssssss. Icons: Yaru [GTK2/3] /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Terminal: gnome-terminal +sssssssssdmydMMMMMMMMddddyssssssss+ CPU: Intel Pentium G3220T (2) @ 2.60 /ssssssssssshdmNNNNmyNMMMMhssssss/ GPU: Intel HD Graphics .ossssssssssssssssssdMMMNysssso. Memory: 1895MiB / 3777MiB -+sssssssssssssssssyyyssss+- `:+ssssssssssssssssss+:` .-/+oossssoo+/-.