zoukankan      html  css  js  c++  java
  • Perl 监控Redis

    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 ."
    ";
        foreach(@lines){
            if(/inet addr:([d.]+)/){
                push @ip,$1 unless $1 =~ /A127.0.0.1z/;
            }
        }
        print "${yellow}HOST: $host => IP: @ip$normal
    ";
        print "-" x 80 ."
    ";
    };
    &basic();
    sub send_mail{
    if (@_ != 2){print "error
    "};
        ($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
    ";
        my $subject = "Subject: zjcap info
    ";
        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("
    
    ");
        $smtp->datasend("$message
    "); # 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
    ";
    $r->quit; 
    };
    
    print "$var
    ";
    if ( defined($var) ){print "redis could connetct
    "}
    else
    {print "redis is lost",send_mail('zhaoyangjian@zjcap.cn',"@ip-redis is lost
    ")};

  • 相关阅读:
    JQuery POST请求乱码...
    open source e-business software
    about tomcat ssl
    使用汉文博士检索汉字
    使用汉文博士检索词条
    安装并运行汉文博士
    汉文博士正式版发布
    汉文博士新测试版0.5.3.2081发布
    汉文博士新测试版0.5.3.2020发布
    汉文博士新测试版0.5.3.2010发布
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351462.html
Copyright © 2011-2022 走看看