#! /usr/bin/perl -w
use strict;
my $file = '/root/smsg/logs/smsg2.log';
my $time = 120;
my (@start, @finish);
my ($send, $up, $report) = @ARGV;
my ($tr, $to, $ts, $tt, $ti) = (-1, -1, -1, 0, 0);
@start = (localtime())[0, 1, 2];
while (1)
{
sleep $time;
open RFILE, "<$file" or die "can not open $file";
while (
{
if (/.+\s(\d+:\d+:\d+).+:\w+\[(\d+)\],\w+\[(\d+)\],\w+\[(\d+)\]/)
{
$tr = $4;
$to = $3;
$ts = $2;
$tt = $1;
}
}
close RFILE;
if ($report < $tr)
{
$report = $tr;
$up = $to;
$send = $ts;
}
elsif ($report == $tr)
{
@finish = split ':', $tt;
last;
}
else
{
next;
}
}
$ti = ($finish[0] - $start[2]) * 3600 + ($finish[1] - $start[1]) * 60 + $finish[2] - $start[0];
printf("\n<----------------report----------------->\n");
printf("start time is %02d:%02d:%02d\n", $start[2], $start[1], $start[0]);
printf("finish time is %02d:%02d:%02d\n\n", $finish[0], $finish[1], $finish[2]);
printf("start Gateway Count is %8d\n", $ARGV[0]);
printf("start MO Count is %8d\n", $ARGV[1]);
printf("start Report Count is %8d\n\n", $ARGV[2]);
printf("last Gateway Count is %8d\n", $send);
printf("last MO Count is %8d\n", $up);
printf("last Report Count is %8d\n\n", $report);
printf("Gateway speed is %8.2f\n", ($send - $ARGV[0]) / $ti);
printf("MO speed is %8.2f\n", ($up - $ARGV[1]) / $ti);
printf("Report speed is %8.2f\n", ($report - $ARGV[2]) / $ti);
printf("<---------------- ends ----------------->\n");