Graphical reporting of data
Till now we have gathered enough data from our systems. We will now plot this data graphically to analyse it in a better way. The tools that we will use here are gnuplot and mrtg for graphical reporting.
gnuplot is a plotting tool that we can operate in one of two modes:
- Interactive mode: Here you issue a command at the gnuplot prompt to adjust a graph to your liking.
- Batch mode: Here you can feed gnuplot the commands from a file to make it generate graphs in a batch.
Let’s gather some data first using the sar command. Then we’ll use the gnuplot command to visualise the data. Run
sar -r 2 100 > ~/meminfo & to collect the data and store it in a file named
meminfo. Remember to set
alias sar="LANG=C sar" so that you have outputs in the 24-hour clock format. Figure 6 shows the output from the
Now, use a text editor (for example, vi) to open the file and remove any non-numeric lines—which basically means the first three lines of Figure 6 need to be deleted.
Make sure you have gnuplot installed. If it is not installed, use your distro’s package manager or download it from www.gnuplot.info.
Create a file using a text editor with the following lines:
set xdata time set timefmt "%H:%M:%S" set xlabel "Time" set ylabel "Memory (in Kb)" plot "meminfo" using 1:2 title "FREE" with lines replot "meminfo" using 1:5 title "BUFFERED" with lines replot "meminfo" using 1:6 title "CACHED MEMORY" with lines
Save this as
myfree.gplot. Now run the command:
gnuplot -persist myfree.gplot
gnuplot will display a graphical view of the memory consumption trend as shown in Figure 7.
In the same manner, we can also display the graph for the disk activities, etc.