perl 监控服务器负载

1、load_monitor_multiple_server.pl

#/usr/bin/perl
require "alarm.pl";#封装了日志和发邮件函数
require "server_config.pl";#服务器列表,ip:port
my $time=localtime;

my $log='./multiple_load_monitor.log';
for $server (sort keys %servers){
        my @ss;
        my $content;
        my @server_port = split ":",$servers{$server};
        if(@server_port>1){
                @ss=split " " ,`/usr/bin/ssh  root\@@server_port[0] -p @server_port[1] "cat /proc/loadavg"`;
                $content = "@server_port[0] current load is $ss[0]";
        }else{
                @ss=split " " ,`/usr/bin/ssh  root\@$servers{$server} "cat /proc/loadavg"`;
                $content = "$servers{$server} current load is $ss[0]";
        }

        if ($ss[0] < 6.5 ){
                 #print 'load is ok!';
                 phpdba_log ($time,$content,$log);
         }elsif ($ss[0]>=6.5){
                phpdba_log ($time,$content,$log);#记录日志
                phpdba_mail_load ($time,$content,$content,$ss[0]);#根据负载及上班状态等情况,判断发送短信或者邮件
        }
}
此条目发表在技术生涯分类目录,贴了标签。将固定链接加入收藏夹。