Thursday 2 January 2014

gnuplot

Here is a very basic notes on the gnuplot to plot your system sar information.

1: You can plot any data output but for example I am using "sar" command to plot sysstem's cpu information.

NOTE, that you can specify any column over here if your output data is not proper. But the data file must content the number values only.

2: If you don't have gnuplot install, then go ahead and install the same.

For sar: [ sudo apt-get install sysstat ]
For gnuplot: [ sudo apt-get install gnuplot ]

Over here I have updated the sar command with alias, so that you should see the time  at 24 hour.

alias sar='LANG=C sar'



NOTE: You can have a gplot file that can carry all the commands that you want.
NOTE: The file extention must be " .gplot "

Example of the .gplot file:

vi cpuinfo.gplot

set xdata time
set timefmt "%H:%M:%S"
set xlabel "TIME"
set ylabel "CPU"
plot "cpuinfo.dat" using 1:3 title "User%" with lines
replot "cpuinfo.dat" using 1:5 title "System%" with lines
replot "cpuinfo.dat" using 1:8 title "Idle%" with lines



# On the above file: we are plotting column number 3, 5 and 8"
If you need to plot more then one value then you need to use "replot" and not the "plot" command.

NOTE: as part of example I have the "cpuinfo.dat" file and "cpuinfo.gplot" at the same location, and you can give any file name what ever you want but the plot script need to have ".gplot" is there.

To get the data, you just need to run the following command. [ NOTE: -persist option will keep the plot open untill you close the same. ]

gnuplot -persist cpuinfo.gplot



On the command line also you can run the same command under "gnuplot" prompt and get the data:

$ gnuplot
gnuplot> set xdata time
gnuplot> set timefmt "%H:%M:%S"
gnuplot> set xlabel "Time"
gnuplot> set ylabel "CPU"
gnuplot> plot "cpuinfo.dat" using 1:3 title "User%" with lines
gnuplot> replot "cpuinfo.dat" using 1:5 title "System%" with lines
gnuplot> replot "cpuinfo.dat" using 1:8 title "Idle%" with lines


Very Imp:
You can not plot non numeric data, so you have to delete the lines that have nun numeric data.


Example the default output of sar might be as:

$ sar -u 1 5 > cpuinfo.dat
Linux 3.8.0-34-generic (amitAsus)     01/02/14     _x86_64_    (8 CPU)

19:46:33        CPU     %user     %nice   %system   %iowait    %steal     %idle
19:46:34        all      3.52      0.00      1.26      0.00      0.00     95.23
19:46:35        all      4.01      0.00      1.00      0.00      0.00     94.99
19:46:36        all      7.66      0.00      1.01      0.00      0.00     91.33
19:46:37        all      5.28      0.00      0.63      0.00      0.00     94.09
19:46:38        all      4.03      0.00      1.13      0.00      0.00     94.84
Average:        all      4.90      0.00      1.00      0.00      0.00     94.10
 

 In the above file you need to delete the first line, the last time and the line where we have the header info.


Example:































Ref:
http://www.youtube.com/watch?v=UEwOc3-VvP4

No comments:

Post a Comment