Chinaunix首页 | 论坛 | 博客
  • 博客访问: 531819
  • 博文数量: 126
  • 博客积分: 851
  • 博客等级: 准尉
  • 技术积分: 1287
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-06 11:21
个人简介

个人最新博客地址http://www.skylway.com/

文章分类

全部博文(126)

文章存档

2016年(2)

2014年(60)

2013年(35)

2012年(29)

分类: Python/Ruby

2012-11-09 11:49:49

#! /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");

阅读(803) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~