#!/usr/bin/perl
#
# Used to check cpu usage and return to stdout
#
$machine = `hostname -s`;
$getcpu = `/usr/bin/sar -u 1 5 | grep Average`;
$getuptime = `/usr/bin/uptime`;
$getcpu =~ /^Average:\s+(\w+)\s+(\d+)\.(\d+)\s+(\d+)\.(\d+)\s+(\d+)\.(\d+)\s+(\d+)\.(\d+)/;
$getcpuusr = $2;
$getcpusys = $6;
print "$getcpuusr\n";
print "$getcpusys\n";
if ($getuptime =~ /^\s+(\d{1,2}:\d{2}:\d{2})\s+up\s+(\d+\s+\w+)/)
{
$utime = $2;
}
else
{
$getuptime =~ /^\s+\d{1,2}:\d{2}:\d{2}\s+up\s+(\d+:\d+)/;
$utime = $1;
}
print "$utime\n";
print "$machine\n";
2008年6月15日 星期日
check cpu usage
grep 個 cpu usage 同埋 uptime 出來, print 去 stdout
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言