Plotting CPU temperature with gnuplot

Good sysadmins take a look daily to log, and they collect a lot of logs, the most of the information collected consists of time series data:
a set of numerical values associated with a sequence of discrete time values.
There are many number of tools for monitoring this data visually as it is collected, most of them are built using the exellent RRDTool, like cacti …
In this article, I’ll introduce you to Gnuplot, focusing specifically on how to plot time series data.
Gnuplot is a portable command-line driven interactive data and function plotting utility.
It has been supported and under development since 1986. Gnuplot supports many types of plots in either 2D and 3D.
It can draw using lines, points, boxes, contours, vector fields, surfaces, and various associated text. It also supports various specialized plot types.

Let’s start our example that is based on reading CPU Temperature Sensor.
We will use lm_sensor a hardware monitoring tool.
Create a cron entry that collect continuously the CPU temperature into a log file /var/log/sensors.log.
(echo `date +%b-%d-%H:%M:%S` | tr -d ‘\ 012’ ; echo -n ‘ ‘; sensors | awk ‘/CPU Temp:/{ print $3 }’ )>> /var/log/sensors.log

After create a file with this contents.
$ cat > temper.conf
set terminal png size 620,360
set xdata time
set timefmt “%b-%d-%H:%M:%S”
set output “temper.png”
# time range must be in same format as data file
set xrange [“AUG-25-00:00:00″:”SEP-05-00:00:00”]
set yrange [0:60]
set grid
set xlabel “Date-Time”
set ylabel “°C”
set title “CPU temperature”
set key left box
plot “/var/log/sensors.log” using 1:2 index 0 title “aldebaran” with lines

Wait for a while for collecting data and tape the following command that will end up with a file called ‘temper.png’.
Use your favorite image viewer to take a look.
$ cat temper.conf | gnuplot

Plotting CPU temperature with gnuplot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s