Perl 监控 web展示
发布时间:2020-12-15 23:45:11 所属栏目:大数据 来源:网络整理
导读:pre name="code" class="sql"my $tom_home='/usr/local/apache-tomcat-7.0.55_8081/webapps/mon';if (-f "$tom_home/file.html"){open FILE,"$tom_home/file.html";close FILE;}jrhapt01:/home/tomcat/mon perl c1.pl jrhapt01:/home/tomcat/mon cat /usr/lo
<pre name="code" class="sql">my $tom_home='/usr/local/apache-tomcat-7.0.55_8081/webapps/mon'; if (-f "$tom_home/file.html"){ open FILE,">$tom_home/file.html"; close FILE;} jrhapt01:/home/tomcat/mon> perl c1.pl jrhapt01:/home/tomcat/mon> cat /usr/local/apache-tomcat-7.0.55_8081/webapps/mon/file.html jrhapt01:/home/tomcat/mon> cat c1.pl my $tom_home='/usr/local/apache-tomcat-7.0.55_8081/webapps/mon'; if (-f "$tom_home/file.html"){ open FILE,">$tom_home/file.html"; close FILE;} jrhapt01:/home/tomcat/mon> cat m1.pl #!/usr/bin/perl use POSIX; use Encode qw/encode decode/; use CGI; my $dir = '/usr/local/apache-tomcat-7.0.55_8081/logs'; my $file = 'catalina.out'; my $tom_home='/usr/local/apache-tomcat-7.0.55_8081/webapps/mon'; $mon_file = "$dir/$file"; $IPMACHINE = "MBANKtest1"; $RTXNO="04657"; my $SDATE = strftime("%Y%m%d%H%M%S",localtime()); $UPLOADPATH = "/data/swap/mbanklog/$IPMACHINE-$SDATE$file"; print "########################################################################################################################n"; print "######监控日志文件: $mon_filen"; print "######监控服务器: $IPMACHINEn"; print "######报警通知腾讯通号码: $RTXNOn"; print "######当前报警时间戳: $SDATEn"; ##########监控关键字,以空格隔开################ @warn_arr = qw/Exception 密码错误 登录失败/; if (-f "$tom_home/file.html"){ open FILE,">$tom_home/file.html"; close FILE;}; foreach $a (@warn_arr) { undef @err_info; open( C,"<","$a.tmp" ); while (<C>) { $count = $_; } print "=========================================================================================================================n"; print "######监控异常关键字: "$a"---数量=$countn"; open( A,"$mon_file" ) || die "$!n"; $i = 0; $num = 0; $b = 0; while (<A>) { $num++; if ( $_ =~ /$a/i ) { $i++; $b = $num } }; if ( $i != 0 && $i != $count && defined($count) ) { open( B,"$mon_file" ) || die "$!n"; while (<B>) { if (($. >= "$b" -2) and ($. <= "$b" + 2) ){push( @err_info,$_ ) }; }; print "######错误信息:@err_infon"; my $q = CGI->new; open (C,">>$tom_home/file.html"); print C ( $q->start_html('warn info')); print C ($q->h1("$a--err_info is @err_info")); print C ($q->end_html); close C; # system("wget -q --spider -t 1 http://10.130.130.248:8012/sendnotify.cgi?title="$IPMACHINE"&msg="$SDATE$filen@err_info"&receiver="$RTXNO""); ## sleep(5); ## system("./putlog "$mon_file" "$UPLOADPATH""); # print "######日志文件已上传至 $UPLOADPATHn"; close B; }else { my $q = CGI->new; open (C,">>$tom_home/file.html"); print C ( $q->start_html('warn info')); print C ($q->h1("$a IS OK")); print C ($q->end_html); close C; } open( D,">","$a.tmp" ); print D ("$in"); }; You have new mail in /var/spool/mail/tomcat ------------------------------------------------------------------------------------------------ jrhapt01:/usr/local/apache-tomcat-7.0.55_8081/webapps> pwd /usr/local/apache-tomcat-7.0.55_8081/webapps jrhapt01:/usr/local/apache-tomcat-7.0.55_8081/webapps> cd mon/ jrhapt01:/usr/local/apache-tomcat-7.0.55_8081/webapps/mon> ls file.html 访问: http://121.40.167.35:8081/mon/file.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |