代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Perl
】
监控网站的性能和 uptime
作者:
gogo
/ 发布于
2014/1/17
/
970
#!/usr/bin/perl usewarnings; usestrict; useTie::File; useNet::SMTP; useLWP::UserAgent; ################################################################# # Program Settings # my $error_log = 'Responser_errors.txt';# File to store errors of program my$input_file='urls.txt';# From where program will read WEB Addresses my$smtp_file='SMTP_Settings.txt';# File for SMTP Settings my$response_limit= 12;#In Seconds # Positively diggit -> SendMail; # 0 -> will not send mail my$send_mail= 1;# my $send_mail = 1; ->SMTP option is ON, # my $send_mail = 0; ->SMTP option is OFF ################################################################## # END OF SETTINGS # Do not edit bellow if you dont understand it. ################################################################## die"File $input_file is not exist\n"unless(-e$input_file); die"SMTP is ON, but file $smtp_file is not exist\n"unless(-e$smtp_file); my$localtime=localtime; our@errors; my($day,$month,$date,$hour,$year) =split/\s+/,scalarlocaltime; my$output_file='report-'.$date.'.'.$month.'.'.$year.'.txt'; my($smtp_host,$recipient,$reverse_path,@all_addr) = (); tie@all_addr,'Tie::File', $input_fileor error("Cant open $input_file to read addresses"); if(-e$output_file) { open(OUT,">> $output_file") or error("Cant open exist file $output_file for append"); }else{ open(OUT,"> $output_file") or error("Cant open new file $output_file for writting"); } my@smtp_settings; if($^O =~ /win/i) { tie@smtp_settings,'Tie::File',$smtp_file,, recsep =>"\012" or error("Cant open $smtp_file to read SMTP settings"); }else{ tie@smtp_settings,'Tie::File',$smtp_file,autochomp =>'0' or error("Cant open $smtp_file to read SMTP settings"); } for(@smtp_settings) { chomp; nextif/^#/; #next if /^$/; if(/^(\w+)\s=\s'(\S+)'/) { $smtp_host=$2if($1eq'SMTPHost'); $recipient=$2if($1eq'Recipient'); $reverse_path=$2if($1eq'Reverse'); } } printOUT"\n+".('-'x 84) ."+\n"; printOUT"|",' 'x 30,"Time: $hour",' 'x 40,"|\n"; printOUT"|",' 'x 10,'HOST',' 'x 37,'STATUS',' 'x 7, "RESPONSE |\n"; printOUT"+".('-'x 84) ."+\n"; for(0 .. $#all_addr) { chop$all_addr[$_]if($all_addr[$_] =~ /\s+$/); nextif($all_addr[$_] eq""); if($all_addr[$_] =~ /^http:\/\/\S+\.\w{2,4}$/) { #address will beginnig withhttp://,next some string # finish with point and 2 to 4 letters check_url($all_addr[$_]);#call subroutine check_url() }else{ my$out_format=sprintf"| %-50.50s %-10s %-20s|\n", $all_addr[$_],"WRONG","N/A"; printfOUT$out_format; printf$out_format; push@errors,"$all_addr[$_] is WRONG Address."; } } my$err=join"\015\012",@errors; my$err_num=scalar@errors;# How match DOWN + WRONG Sites have $send_mail= 0unless$err_num; untie@all_addror error("Unable to close file $input_file"); if($send_mail) { my$smtp= Net::SMTP->new($smtp_host, -Debug=>1, -Timeout=>20, -Hello=>"$smtp_host") or error("Cant connect to $smtp_host"); # Begin Compare mail message my$msg= <<__END_OF_MAIL__; To:$recipient Subject:$err_numError Sites |$localtime. $localtime $err __END_OF_MAIL__ # End Compare $smtp->mail("$reverse_path") or error("Failed to specify a reverse-path");# If all is OK $smtp->to($recipient) or error("Failed to specify a recipient");# that will $smtp->data([$msg]) or error("Failed to send a message");# send mail $smtp->quit or error("Failed to quit");# to You }else{ print"Send Mail is OFF\n"if$err_num;# If you do not wish to receive mail } closeOUT or error("Unable to close file $output_file"); print"\nProcess FINISH\n"; subcheck_url {# subroutine who check given URL my$target=$_[0]; my$ua= LWP::UserAgent->new; $ua->agent("$0/0.1 ".$ua->agent); my$req= HTTP::Request->new(GET =>"$target"); $req->header('Accept'=>'text/html');#Accept HTML Page # send request my$start=time;# Start timer my$res=$ua->request($req); # check the outcome if($res->is_success) { # Success....all content of page has been received my$time=time;# End timer my$out_format; $time= ($time-$start);# Result of timer if($response_limit&& ($response_limit<=$time)) { push(@errors,"Slow response from $target\: $time seconds"); $out_format=sprintf"| %-50.50s %-10s %-20s |\n", $target,"SLOW","Response $time seconds"; }else{ $out_format=sprintf"| %-50.50s %-10s %-20s |\n", $target,"ACCESSED","Response $time seconds"; } printOUT$out_format;# write to file print$out_format;# print to console }else{# Error .... Site is DOWN and script send e-mail to you.. my$out_format=sprintf"| %-50.50s %-10s %-20s |\n", $target,"DOWN"," N/A"; push(@errors,"$target is DOWN.".$res->status_line) or error("Cannot push error for DOWN"); printOUT$out_format;# write to file print$out_format;# print to console } } suberror {# subroutine who print in Error Log my$error_msg=shift; openERR,">> $error_log" ordie"Cannot open log file $error_log : $!\n"; printERR"$localtime\: $error_msg : $!\n"; closeERR ordie"Cannot close log file $error_log : $!\n"; }
试试其它关键字
监控网站
同语言下
.
获取本机所有IP和设备的绑定情况
.
生成隨機密碼
.
取文件的最后修改时间
.
获取本机所有IP和设备的绑定情况
.
将perl脚本变成乱糟糟的一团
.
从 HTML网页中解析出链接
.
使用 HTTP::Request 请求 URL 并将响应保存到文件
.
使用指定的User-Agent抓取网页
.
使用 Net::SMTP发送邮件
.
编写的一个简单 Web服务器
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
gogo
贡献的其它代码
(
7
)
.
执行Linux安装程序和脚本
.
批量赋予可执行权限
.
通过IMAP接收、处理邮件
.
监控网站的性能和 uptime
.
删除文件
.
扫描apache日志,寻找type==1的日志,写到数据库里.
.
从文件中提取字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3