mabbacc.com

'CPU'에 해당되는 글 1건

  1. 2010/04/10 Linux CPU 모니터 하다가 메일 보내기
개인적으로 사용하기 위해서 대충 만든겁니다.
대강 대강....
( 지금 리눅스 서버에서 돌아가고 있는 작업이 끝나야 제가 다음 작업할 수 있기 때문에
그렇게 모니터링 하게 했습니다.)

참고글 1 :
Perl script to monitor disk space and send an email
http://www.cyberciti.biz/tips/howto-write-perl-script-to-monitor-disk-space.html

참고글 2 : Linux CPU usage monitor
http://www.perlmonks.org/?node_id=464330



내가 만든 코드 1
cpu_checker.pl
#!/usr/bin/perl
use strict;
use warnings;

open(INFIL,"< /proc/stat") or die("Unable To Open /proc/stat: $!\n");
# while()
{
     my @loads;
     my $cpuload = 0;
     for (0,1)
     {
       my $in = <INFIL>;
       (warn "something wrong!\n"), next unless $in =~ /^cpu\b/;
       push @loads,  ($in =~ /\d+/g)[0..2];
       seek INFIL, 0, 0;
       select (undef, undef, undef, 1) unless $_;
     }
     redo unless defined $loads[0];
     for (0..2) { $cpuload += ($loads[$_+3] - $loads[$_]); }
         print "$cpuload\n";
}
close(INFIL);

내가 만든 코드 2
cpu_monitor.pl
#!/usr/bin/perl

use strict;
use warnings;

# warning level
my $warning_level = 50;

# email setup
my $to = '나의 이메일';
my $from = '나의 이메일';
my $password = '나의 패스워드';

my $subject = 'LOW CPU';

# get CPU
my ($cpu_util) = `./cpu_checker.pl`;

#compare
if ( $cpu_util < $warning_level )
{
  my $out = sprintf ( "TRUE mysqld indexing work %0.2f%% < %0.2f%%\n", $cpu_util, $warning_level);
  # TEST - print $out;

} else {
  my $out = sprintf ( "FALSE mysqld indexing work %0.2f%% < %0.2f%%\n", $cpu_util, $warning_level);
  # TEST - print $out;
}
  open (MAIL, "|/usr/bin/sendEmail -f $from -t $to -s smtp.gmail.com -o tls=yes -xu $from -xp $password -u \"$subject\" -m \"$out\" ");
  close(MAIL);


둘다 실행권한 주기
cmd> chmod +x cpu_*.pl

Cron job 에 등록하기
cmd > crontab -e
@hourly /root/cpu_monitor.pl
root@Android-server:~# crontab -l
# m h  dom mon dow   command
@hourly /root/cpu_monitor.pl
root@Android-server:~#
크리에이티브 커먼즈 라이센스
Creative Commons License
2010/04/10 14:50 2010/04/10 14:50
Posted by mabbacc
My Space l 2010/04/10 14:50
1 

카테고리

전체 (84)
Notice (1)
My Angels (1)
My Space (40)
My Entertainments (10)
My Spirits are made of ... (10)
Do not touch me. (0)
My VIM (5)
My Workstation (11)
My Mac Life (3)
My Will (0)

달력

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Textcubeget rsslazylogs

공지 사항

최근에 달린 댓글

최근에 받은 트랙백

Statistics Graph