Performance Monitoring and Reporting

October 9, 2016 by S4

Filed under Uncategorized

Last modified October 9, 2016

Performance Monitoring and Reporting

Introduction

The purpose of the document is to show how using scripts like awk and perl CPU performance data of a AIX system can be collected and reported in graphical form i.e. in form of charts. It uses graph module of Perl to create graphs. The graph module is not a part of standard Perl distribution but can be installed from http://theoryx5.uwinnipeg.ca/ppms/GD.ppd

Procedure

The data is collected at regular intervals using vmstat and scheduling in crontab. Once the data is stored in a file, calculate the daily average using awk and display the data in chart on web.

1. Collect data using vmstat tool. The script is to be scheduled to run at hourly basis.

#genstat.sh

dt=”Date: `date \”+%D\”`”
echo $dt
vmstat 1 11|awk ‘{if(NR!=4){print $0}}’ #leave the first record

The output is collected in a file called ‘vmdata’.

2. Calculate the daily average using the following script.

#fmtvm.awk
$1~/Date/{
ndate=$2
if(ndate!=odate){
if(count!=0){
usr=usr/count;sys=sys/count;idl=idl/count;wat=wat/count;
print odate” “usr” “sys” “idl” “wat;
usr=0;sys=0;idl=0;wat=0;count=0;
}
odate=ndate;
}
}
$1~/[0-9]+/{
usr+=$14;
sys+=$15;
idl+=$16;
wat+=$17;
count++;
}
END{
if(count!=0){
usr=usr/count;sys=sys/count;idl=idl/count;wat=wat/count;
print odate” “usr” “sys” “idl” “wat;
}
}

The awk script is run as follows
awk –f fmtvm.awk vmdata

A sample output of the command is displayed as below. The column headings are not a part of the data, but are given for the sake of understanding.

Date %usr %sys %idle %wait
11/06/15 0.1 0.4 99 0
11/07/15 0.1 0.4 99 0
11/08/15 0.3 0.2 98.9 0
11/09/15 1.2 0.5 98.3 0
11/10/15 0.5 0.4 98 0

3. The web server in our case is Apache configured on windows. The data from Unix server is FTP to the windows server for the purpose of reporting. The data is stored in a text file(say vmdata.txt). The following Perl script, kept in cgi-bin directory, reads the data from the file into arrays which are passed as source to methods creating Graph and finally the graph is displayed on the browser.

#graph.pl

#! C:\Perl\bin\perl.exe -w
use strict;

use CGI;
use GD::Graph::linespoints;

my $cgi = CGI->new();
print $cgi->header( -type => “image/png” );

my @fil;
my @xlabels ;
my @pusr ;
my @psys ;
my @pidl ;
my @pwat;
my @data ;

open(FL,”< vmdata.txt"); while()
{
my($xlabel,$pus,$psy,$pid,$pwat)=split(/ /,$_);
push(@xlabels,$xlabel);
push(@pusr,$pus);
push(@psys,$psy);
push(@pidl,$pid);
push(@pwat,$pwat);

}
close(FL);

@data = ( \@xlabels, \@pusr, \@psys, \@pidl );

my $graph = GD::Graph::linespoints->new( 800, 600 );
$graph->set_legend( “User”, “System”, “Idle” );

$graph->set( title => “Percentage CPU Utilisation Report 2005”,
y_label => “Percentage Utilisation”,
transparent => 0,
legend_placement => “RT” ,
show_values => 1,
values_space => 10
);

print $graph->plot(\@data)->png();

4. The web server chosen is Apache on Windows. The above script is kept in cgi-bin directory the data file ‘vmdata.txt’ is also kept in the cgi-bin directory. And an interface is created for calling the script.



<br /> Perl Graph Module<br />



Perl Graph Module



performance monitor

performance monitor


Summary/Conclusion

The document show the capability of Graph module of Perl which can be used to leverage simple graphical reports required in day today functioning.

Clicking on button shows the graph

performance monitor

performance monitor

Leave a Comment