hyzqb 发表于 2018-9-1 10:27:20

perl 监控log统计脚本

#!/usr/bin/perl  my $web=0;
  my $pop3=0;
  my $smtp=0;
  my $master=0;
  my $slave=0;
  my $resin=0;
  my($curlogfile) =@ARGV;
  open(FILE,$curlogfile);
  while(){
  if ($_=~/down/){
  $totaltimes++;
  }
  chomp();
  @items=split(/\ /);
  my $service=$items;
  my $date=$items;
  @newitem1=split(/\:/,$service);
  $ip=$newitem1;
  #      print $ip."\n";
  #      sleep (5);
  my $port=$newitem1;
  @newitem2=split(/\-/,$date);
  my $time=$newitem2;
  if ($port eq "2000"){
  $master=$master+1;
  }
  if ($port eq "9002"){
  $slave=$slave+1;
  }
  if ($port eq "80"){
  $web=$web+1;
  }
  if ($port eq "25"){
  $smtp=$smtp+1;
  }
  if ($port eq "110"){
  $pop3=$pop3+1;
  }
  if ($port=~/6802|6803|6804|6805/){
  $resin=$resin+1;
  }
  if ( defined( $totalip{$ip} ) ){
  $totalip{$ip}=$totalip{$ip}+1;
  }else{
  $totalip{$ip}=1;
  }
  #      print $ip."    ".$port."    ".$port{$ip}."\n";
  }
  close(FILE);
  print "总故障次数:".$totaltimes."\n";
  if ($web gt 0){
  print "WEB故障次数:".$web."\n";
  }
  if ($pop3 gt 0){
  print "POP3故障次数:".$pop3."\n";
  }
  if ($smtp gt 0){
  print "SMTP故障次数:".$smtp."\n";
  }
  if ($resin gt 0){
  print "RESIN故障次数:".$resin."\n";
  }
  if ($master gt 0){
  print "MASTER故障次数:".$master."\n";
  }
  if ($slave gt 0){
  print "SLAVE故障次数:".$slave."\n";
  }
  print "故障ip:"."      "."故障次数\n";
  foreach $key (sort keys %totalip) {
  $num = $totalip{$key};
  print $key."".$num."\n";
  }

页: [1]
查看完整版本: perl 监控log统计脚本