perlscript - Perl script appending date -


am running perl script ever day on server , getting below output script. trying modify script include current hour part of output. how can go doing this?

this current script:

#!/usr/bin/perl #prism performance log parser  use strict;  $cbal_total; $cbal_count =0; $stck_total = 0; $stck_count =0; $chg_total = 0; $chg_count =0; $rmac_total = 0; $rmac_count =0; $rmd_total = 0; $rmd_count =0; $cbalt;  $stckt; $rmact; $rmdt; $chgt; $total; $count; $cbal; $stck; $hour;   $chg; $rmac; $rmd;  $lesthresh=0; $gtthresh=0; $stck_lesthresh=0; $stck_gtthresh=0; $rmd_lesthresh=0; $rmd_gtthresh=0; $chg_lesthresh=0; $chg_gtthresh=0; $rmac_lesthresh=0; $rmac_gtthresh=0;  %checkbal; %subtypecheck; %charging; %remoteact; %remotedct;  $chgkey; $cbalkey; $stckkey; $rmackey; $rmdkey;  @value; $ct; $component; $component2;  while (my $line =<>) {     chomp;     s/\r//g;     @f = split(/\|/, $line);     $i;     $hour = substr($f[0],11,2);      ($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 stck\n"; } foreach (sort keys %checkbal){     print $_.",".$checkbal{$_}."\n"; } 

current output:

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 

desired output:

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 

to current hour, use time::piece

 use strict;  use warnings;   use time::piece;   print localtime->strftime("%h"), "\n"; 

how insert functionality script exercise you.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -