use Redis;
use Sys::Hostname;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
sub basic() {
$host = hostname;
@lines=qx|/sbin/ifconfig|;
@ip;
print "-" x 80 ."\n";
foreach(@lines){
if(/inet addr:([\d.]+)/){
push @ip,$1 unless $1 =~ /\A127.0.0.1\z/;
}
}
print "${yellow}HOST: $host => IP: @ip$normal\n";
print "-" x 80 ."\n";
};
&basic();
sub send_mail{
if (@_ != 2){print "error\n"};
($m,$n) = @_;
my $to_address = $m;
my $CurrTime = time2iso(time());
my $to_address = $m;
my $mail_user = 'zhaoyangjian@zjcap.cn';
my $mail_pwd = 'xxxxx';
my $mail_server = 'smtp.exmail.qq.com';
my $from = "From: $mail_user\n";
my $subject = "Subject: zjcap info\n";
my $info = "$CurrTime--$n";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("\n\n");
$smtp->datasend("$message\n"); # set content
$smtp->dataend();
$smtp->quit();
};
$var;
eval{
my $r = Redis->new( server => "127.0.0.1:6379",reconnect => 1,every=>60) or (die "can't connect to redis");
$r = Redis->new( password => 'xxxx' );
$var=$r->get('test');
print "\$var is $var\n";
$r->quit;
};
print "$var\n";
if ( defined($var) ){print "redis could connetct\n"}
else
{print "redis is lost",send_mail('zhaoyangjian@zjcap.cn',"@ip-redis is lost\n")};
Perl 监控Redis
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
perl 监控发邮件
perl 监控发邮件
监控 perl -
perl 监控日志告警
my $dir = '/usr/local/apache-tomcat-7.0.55_8082/logs';my $SDATE = strftime("%Y-%m-%d",localtime());my $fi...
java tomcat apache spring i++ -
perl 监控数据变化
!/usr/bin/perluse stri...
sql 赋值 perl mysql oracle