Create a graph of your system’s performance
You should have Gnuplot installed on your computer before you proceed. We’ll give you a quick starter to give you some basic familiarity with the workings of Gnuplot before we proceed with creating a script to generate graphs from the data we collected in the previous step.
Gnuplot script
We will use a few scripts like the ones on the next page to build a graph from the data we gathered using Dstat.
First, before we get to the graph-building scripts, you need to run the following shell command to strip the first two lines of the data in the ‘dstat.dat’ file, as they will hamper the graph-building process. The following script will search for lines containing the terms ‘time’ and ‘date’, delete these lines and save the output in a new file called ‘stat.dat’.
# grep -Ev ‘time|date’ dstat.dat > stat.dat
Now we’ll write three Gnuplot scripts which will take the data file ‘stat.dat’ as input and generate three graphs, one each for the CPU, memory and network bandwidth usage. In brief, what we do in these scripts is we first set the title, the x axis and the y axis, and the export format settings as we want them to be. Then we tell Gnuplot to use the file ‘stat.dat’ as data input and which columns to use to plot the respective graphs. Gnuplot takes care of the rest.
#!/usr/bin/gnuplot
set terminal png
set output “cpu.png”
set title “CPU usage”
set xlabel “time”
set ylabel “percent”
set xdata time
set timefmt “%d-%m %H:%M:%S”
set format x “%H:%M”
plot “stat.dat” using 1:3 title “system” with lines, \
“stat.dat” using 1:2 title “user” with lines, \
“stat.dat” using 1:4 title “idle” with lines
The second script…
#!/usr/bin/gnuplot
set terminal png
set output “memory.png”
set title “memory usage”
set xlabel “time”
set ylabel “size(MB)”
set xdata time
set timefmt “%d-%m %H:%M:%S”
set format x “%H:%M”
plot “stat.dat” using 1:8 title “used” with lines, \
“stat.dat” using 1:9 title “buff” with lines, \
“stat.dat” using 1:10 title “cach” with lines, \
“stat.dat” using 1:11 title “free” with lines
This one generates a graph showing the system’s usage of memory
And the third one…
#!/usr/bin/gnuplot
set terminal png
set output “network.png”
set title “network”
set xlabel “time“
set ylabel “size(k)“
set xdata time
set timefmt “%d-%m %H:%M:%S“
set format x “%H:%M“
plot “stat.dat“ using 1:11 title “send“ with lines, \
“stat.dat“ using 1:12 title “recv“ with lines
And this script creates a graph for the network bandwidth usage.
Copy these scripts into the folder that contains ‘stat.dat’, which has the monitoring results from Dstat. Grant executable permissions to the shell scripts with the following command:
# chmod +x cpu.sh memory.sh network.sh
Now run the three scripts to generate the graphs:
# ./cpu.sh; ./memory.sh; ./network.sh
If all went well you should see three new files: cpu.png, memory.png, and network.png. Congratulations, you now have your system-monitoring information in neat-looking graphs!













Inspired by this article i tried to make a finer script on similar lines
Have a look : http://h3manth.com/content/plotting-performance-graph-gnulinux-box
Inspired by this article i have tried to make a single script, have a look here:
http://h3manth.com/content/plotting-performance-graph-gnulinux-box
Useful. Pity the editor changed all the ” into “ and ” so that the scripts don’t actually work. People who publish Linux articles should know about this.
R.
Works great! … Did need to replace the double quotes in the three scripts on page 4 with single quotes, though.
Works great! … Did need to replace the double quotes in the three scripts on page 4 with single quotes, though, and vice versa on the grep line.
Good stuff. Thanks.
While understanding how this task can be performed is useful, perhaps installing a FOSS tool like SysUsage http://freshmeat.net/projects/sysusage/ to create performance graphs would result in greater usability?
Is another and interesting way to measure things about your server, like rrdtool do. Congratulations for the clear and easy to follow article!
[...] Create a graph of your system’s performance [...]
[...] Create a graph of your system’s performance [...]
Nice and practical article. Adding “set grid” to the scripts would make the graphs look nicer.
What's your opinion?