-3

我每天都在我的服务器上运行这个 perl 脚本,并得到脚本的以下输出。我正在尝试修改脚本以将当前时间也包含在输出中。我该怎么做呢?

这是我当前的脚本:

#!/usr/bin/perl
#Prism Performance log Parser

use strict;

my $cbal_total;
my $cbal_count =0;
my $stck_total = 0;
my $stck_count =0;
my $chg_total = 0;
my $chg_count =0;
my $rmac_total = 0;
my $rmac_count =0;
my $rmd_total = 0;
my $rmd_count =0;
my $cbalT;

my $stckT;
my $rmacT;
my $rmdT;
my $chgT;
my $total;
my $count;
my $cbal;
my $stck;
my $hour;


my $chg;
my $rmac;
my $rmd;

my $lesThresh=0;
my $gtThresh=0;
my $stck_lesThresh=0;
my $stck_gtThresh=0;
my $rmd_lesThresh=0;
my $rmd_gtThresh=0;
my $chg_lesThresh=0;
my $chg_gtThresh=0;
my $rmac_lesThresh=0;
my $rmac_gtThresh=0;

my %CheckBal;
my %SubTypeCheck;
my %charging;
my %remoteAct;
my %remoteDct;

my $chgkey;
my $cbalkey;
my $stckkey;
my $rmackey;
my $rmdkey;

my @value;
my $ct;
my $component;
my $component2;

while (my $line =<>) {
    chomp;
    s/\r//g;
    my @f = split(/\|/, $line);
    my $i;
    $hour = substr($f[0],11,2);

    for ($i==0;$i<=100; $i++) {
        if (($f[$i]=~m/CBAL/) && ($f[$i]!~m/CBAL,100/)) {
            $component="CBAL";
            $cbal=$f[$i];
            $cbalkey="$hour,$component";
            if (!exists($CheckBal{$cbalkey})) {
                $cbal_count=0;
                $cbal_total=0;
                $lesThresh=0;
                $gtThresh=0;
            }
            $cbalT = substr($cbal,index($cbal,",T=")+3,index($cbal,"\n"));
            if ($cbalT <= 300) {
                $lesThresh++;
            }else{
                $gtThresh++
            }
            $cbal_total +=$cbalT;
            $cbal_count ++;
            #$CheckBal{$cbalkey} =($cbal_total).",".($cbal_count).",".($lesThresh).",".$gtThresh.",".($cbal_total/$cbal_count);
            $CheckBal{$cbalkey} =($cbal_count).",".($cbal_total).",".($cbal_total/$cbal_count).",".($lesThresh).",".$gtThresh;

        }elsif($f[$i]=~m/STCK/){
            $component="STCK";
            $stck=$f[$i];
            $stckkey="$hour,$component";
            if (!exists($SubTypeCheck{$stckkey})) {
                $stck_count=0;
                $stck_total=0;
                $stck_lesThresh=0;
                $stck_gtThresh=0
            }
            $stckT = substr($stck,index($stck,",T=")+3,index($stck,"\n"));
            if ($stckT <= 300) {
                $stck_lesThresh++;
            }else{
                $stck_gtThresh++
            }
            $stck_total +=$stckT;
            $stck_count ++;
#           $SubTypeCheck{$stckkey} =($stck_total).",".($stck_count).",".($stck_lesThresh).",".$stck_gtThresh.",".($stck_total/$stck_count);
            $SubTypeCheck{$stckkey} =($stck_count).",".($stck_total).",".($stck_total/$stck_count).",".($stck_lesThresh).",".$stck_gtThresh;

        }elsif($f[$i]=~m/CHG/){
            $component="CHG";
            $chg=$f[$i];
            $chgkey="$hour,$component";
            if (!exists($charging{$chgkey})) {
                $chg_count=0;
                $chg_total=0;
                $chg_lesThresh=0;
                $chg_gtThresh=0
            }
            $chgT = substr($chg,index($chg,",T=")+3,index($chg,"\n"));
            if ($chgT <= 300) {
                $chg_lesThresh++;
            }else{
                $chg_gtThresh++
            }
            $chg_total +=$chgT;
            $chg_count ++;
#           $charging{$chgkey} =($chg_total).",".($chg_count).",".($chg_lesThresh).",".$chg_gtThresh.",".($chg_total/$chg_count);
            $charging{$chgkey} =($chg_count).",".($chg_total).",".($chg_total/$chg_count).",".($chg_lesThresh).",".$chg_gtThresh;
        }elsif(($f[$i]=~m/RMAC/) && ($f[$i]!~m/RMAC,96/)){
            $component="RMAC";
            $rmac=$f[$i];
            $rmackey="$hour,$component";
            if (!exists($remoteAct{$rmackey})) {
                $rmac_count=0;
                $rmac_total=0;
                $rmac_lesThresh=0;
                $rmac_gtThresh=0
            }
            $rmacT = substr($rmac,index($rmac,",T=")+3,index($rmac,"\n"));
            if ($rmacT <= 300) {
                $rmac_lesThresh++;
            }else{
                $rmac_gtThresh++
            }
            $rmac_total +=$rmacT;
            $rmac_count ++;
#           $remoteAct{$rmackey} =($rmac_total).",".($rmac_count).",".($rmac_lesThresh).",".$rmac_gtThresh.",".($rmac_total/$rmac_count);
            $remoteAct{$rmackey} =($rmac_count).",".($rmac_total).",".($rmac_total/$rmac_count).",".($rmac_lesThresh).",".$rmac_gtThresh;

        }elsif(($f[$i]=~m/RMD/) && ($f[$i]!~m/RMD,96/)){
            $component="RMD";
            $rmd=$f[$i];
            $rmdkey="$hour,$component";
            if (!exists($remoteDct{$rmdkey})) {
                $rmd_count=0;
                $rmd_total=0;
                $rmd_lesThresh=0;
                $rmd_gtThresh=0
            }
            $rmdT = substr($rmd,index($rmd,",T=")+3,index($rmd,"\n"));
            if ($rmdT <= 300) {
                $rmd_lesThresh++;
            }else{
                $rmd_gtThresh++
            }
            $rmd_total +=$rmdT;
            $rmd_count ++;
#           $remoteDct{$rmdkey} =($rmd_total).",".($rmd_count).",".($rmd_lesThresh).",".$rmd_gtThresh.",".($rmd_total/$rmd_count);
            $remoteDct{$rmdkey} =($rmd_count).",".($rmd_total).",".($rmd_total/$rmd_count).",".($rmd_lesThresh).",".$rmd_gtThresh;

        }


    }

}


print "Balance Check\n";
print "Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms\n";
unless(%CheckBal){
    print "No record found for STCK\n";
}
foreach (sort keys %CheckBal){
    print $_.",".$CheckBal{$_}."\n";
}

电流输出:

Balance Check
Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms
06,CBAL,17987,13131831,730.073441930283,4295,13692
07,CBAL,17911,13579801,758.182178549495,3970,13941
08,CBAL,228,98643,432.644736842105,100,128

期望的输出:

Balance Check
date,Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms
20140528,06,CBAL,17987,13131831,730.073441930283,4295,13692
20140528,07,CBAL,17911,13579801,758.182178549495,3970,13941
20140528,08,CBAL,228,98643,432.644736842105,100,128
4

1 回答 1

0

要获取当前时间,请使用Time::Piece

 use strict;
 use warnings;

 use Time::Piece;

 print localtime->strftime("%H"), "\n";

如何将该功能插入到您的脚本中是您的练习。

于 2014-05-29T16:36:42.717 回答