• Mojo 分析日志接口


    #!/usr/bin/perl
    #取文件行数
    ##循环开始清空文件
    use POSIX;
    use DBI;
    my $dir  = '/data01/applog_backup';
    my $file = "$ARGV[0]";
    my $SDATE = strftime("%Y-%m-%d",localtime());
    my $XDATE = strftime("%Y%m%d%H%M%S",localtime());
    my $mon_file = "$dir/$file";
    my $USER="$ARGV[1]";
    my $IP="$ARGV[2]";
    my $ENV="$ARGV[3]";
    
    my $dbUser='DEVOPS';
    my $user="root";
    my $passwd="1234567";
    my $dbh  = DBI->connect("dbi:mysql:database=$dbUser;host=192.168.32.161;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    $dbh->do("SET NAMES utf8");   
    open FILE,">tmp.out";
    close FILE;
    open( A, "<", "count.txt" );
                while (<A>) 
    			{
                $count = $_;
                };
    print "上次记录的记录数为$count
    ";
    
    
    open(my $fh, '<', "$mon_file");
    $. = 0;
    while (<$fh>) {
        ($num=$.) if eof;
                  };
    print "文件最新的记录数为$num"."
    ";
        open( B, ">", "count.txt" );
        print B ("$num
    ");
    
    	
    ###获取增量记录
    if ( $count  && $num != $count && $num !=0  )
    { 
         print "开始处理
    ";
         open( C, "<", "$mon_file" ) || die "$!
    ";
         while (<C>) 
    	   {
                 if  ($. > "$count" )
    			 { 
                  open( D, ">>", "tmp.out" );
                  print D ("$_");
                 }
            }
    };
                  close D;
    ##########监控关键字,以空格隔开################
    my @warn_arr = qw/Exception Err/;
    my @exp=qw/testscan HandleProxyTradeGroup/;
    
    ##$i 是匹配的次数,$b是最后一个匹配的行HandleProxyTradeGroup
    foreach $a (@warn_arr)
    {
                   my  $i   = 0;
                   my  $num = 0;
                   my     $b = 0;
                   open( D, "<", "tmp.out" ) || die "$!
    "; 
                   while (<D>) 
                      {
                    my @err_info=();
                                 $num++;
                     if  (( $_ =~ /$a/i )  and   ($_ !~ /HandleProxyTradeGroup/))
                                 {
                                 $b = $num ;
                                 print "$b is $b
    ";
                                 open( E, "<", "tmp.out" ) || die "$!
    ";
                                 while (<E>) {
                                $_ =~ s/'//g;
                                if  (($. >= "$b") and  ($. <= "$b" + 5) ){push( @err_info, $_ ) };};
                                 close E;
                                 chomp @err_info;
    
                                 print @err_info;
                                 print "
    ";
                                 $dbh->do("INSERT INTO err_info(host_name,host_ip,v_date,info,env)  values('$USER','$IP','$XDATE','@err_info','$ENV')") or die($DBI::errstr);
                                
                                };
                       };
                                close D;
     };
    

  • 相关阅读:
    企业级性能、安全可靠 阿里云发布企业级大数据平台开发者版
    阿里云的重大战略调整,“被集成”成核心,发布SaaS加速器助力企业成长
    阿里云MVP北京闭门会圆满落幕 多把“利剑”助力开发者破阵蜕变
    Lesson 1 Nehe
    字符串的基本操做
    字符串的基本操做
    字符串的基本操做
    glBlendFunc() opengl 混合
    glBlendFunc() opengl 混合
    glBlendFunc() opengl 混合
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199843.html
Copyright © 2020-2023  润新知