Create a graph of your system’s performance
Use Dstat and Gnuplot to monitor performance, then turn that information into neat-looking graphs that anyone, even your manager, can understand…
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!
Nice and practical article. Adding “set grid” to the scripts would make the graphs look nicer.
Good article – similar to collectl but different. dstat reminds me a lot of collectl which does similar kinds of output but also provides provided a lot more detail, at least from a cursory read of the dstat website.
Collectl would refer to the dstat output as ‘brief’ mode – great for a high level view of what’s going on but then you can also choose ‘verbose’ mode which shows a lot more data elements for each type of component you’re looking at and far too much to fit on one line. Then there’s ‘detail’ format which breaks down the verbose data by individual CPU, network or disk.
Collectl also handles InfiniBand and Lustre data, something critical to HPC environments which was the initial target market.
The collectl-utils rpm provides a tool called colplot, which is basically a web-based front-end to gnuplot. It has intimate knowledge of the types of data collectl collects, so you click a few check boxes and next thing you know some pretty cool plots show up.
http://collectl.sourceforge.net/ and
http://collectl-utils.sourceforge.net/
-mark
Hi,
A fast and good solution to generate graphs from dstat log files is Vmstax.
No configuration, just upload your log file and retrieve the generated graphs as png.
More information at :
http://www.michenux.net/dstat-graph-using-vmstax-154.html
Best regards