#!/usr/bin/perl
#****************************************************************#
# ScriptName: rdsstat
# Author: tangcheng
# Create Date: 2010-07-19
# Modify Author: tangcheng
# Modify Date: 2010-07-19
# Function:
#***
use POSIX qw(strftime);
use Time::Local;
$argc = @ARGV;
if($argc != 2)
{
usage();
exit(1);
}
$interval=$ARGV[0];
$count=$ARGV[1];
if($interval <=0 or $count <=0)
{
usage();
exit(1);
}
my @rdsstats;
my @prerdsstats;
my $i;
my $strtime;
@prerdsstats=getstats();
print " time Xmit bytes Xmit packets Recv bytes Recv packets\n";
print "------------------- ------------ ------------ ------------ ------------\n";
$i=0;
for(;$i<$count;$i++)
{
sleep($interval);
@rdsstats=getstats();
$strtime= strftime "%Y-%m-%d %H:%M:%S", localtime();
printf("%19s %12d %12d %12d %12d\n",
$strtime,
($rdsstats[0]-$prerdsstats[0])/$interval,
($rdsstats[1]-$prerdsstats[1])/$interval,
($rdsstats[2]-$prerdsstats[2])/$interval,
($rdsstats[3]-$prerdsstats[3])/$interval);
$prerdsstats[0]=$rdsstats[0];
$prerdsstats[1]=$rdsstats[1];
$prerdsstats[2]=$rdsstats[2];
$prerdsstats[3]=$rdsstats[3];
if( ($i+1) % 10 == 0)
{
print " time Xmit bytes Xmit packets Recv bytes Recv packets\n";
print "------------------- ------------ ------------ ------------ ------------\n";
}
}
exit 0;
sub usage
{
print "Usage: rdsstat <interval> <count>\n";
print "Example: rdsstat 1 10000\n";
}
sub getstats
{
my @res;
my $rdsinfo;
my $line;
my @lines;
my @cells;
my $cellcnt;
$rdsinfo=`cat /proc/driver/rds/stats`;
@lines = split("\n", $rdsinfo);
foreach $line(@lines)
{
chomp($line);
$line =~ s/^\s+//;
$line =~ s/\s+$//;
@cells=split(/\s+/,$line);
$cellcnt=@cells;
if($cellcnt != 3)
{
next;
}
if($cells[0] eq "Xmit" and $cells[1] eq "bytes")
{
$res[0]=$cells[2];
}
elsif($cells[0] eq "Xmit" and $cells[1] eq "packets")
{
$res[1]=$cells[2];
}
elsif($cells[0] eq "Recv" and $cells[1] eq "bytes")
{
$res[2]=$cells[2];
}
elsif($cells[0] eq "Recv" and $cells[1] eq "packets")
{
$res[3]=$cells[2];
}
}
return @res;
}
|