LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Resource monitor (https://www.linuxquestions.org/questions/linux-software-2/resource-monitor-63642/)

Bilb 06-04-2003 11:47 AM

Resource monitor
 
Hi,

Basically im after a little script or program that will email me if ever the system gets overloaded.

Anyone know of any?

david_ross 06-04-2003 12:21 PM

I don't know of one but if you mean like CPU usage then you could just write something to monitor the output from sar.

Bilb 06-06-2003 03:04 PM

I've tried with sar but still not the best with scripting,

I've tried doin
sar 2 5 > tmp0.log
chk=`tail -c 6 tmp0.log`

but I cant seem to get the if command to work with it.

I've also tried awk '/Average/ { t=$6 }' tmp0.log but with no luck :(

david_ross 06-09-2003 12:40 PM

Sorry - I've been away for a few days.

What is it you want to extract from the output?

Bilb 06-09-2003 01:29 PM

In the end I would like it to email me with the box IP if the CPU/'s gets overloaded.

david_ross 06-09-2003 01:58 PM

Here is a perl script
Code:

#!/usr/bin/perl

# Get the CPU usage
@sar = `sar 1 1`;

# Extract the average CPU usage
($ave) = $sar[@sar-1] =~ /.* (.*)\n/;

# If there is only 5% CPU available then...
if($ave < "5"){

# Get the ip info
@ipconf = `ifconfig`;

# Send the ip info
open(MAIL, "|/usr/lib/sendmail -t");
print MAIL "To: someone\@somewhere.com\n";
print MAIL "From: someone\@somewhere.com\n";
print MAIL "Subject: CPU running at over 90% CPU\n\n";
print MAIL @ipconf;
close(MAIL);
}

exit;


Bilb 06-10-2003 08:58 AM

Thx alot!
u've saved me a few more migraines :)

I'll give it a go when i get a mo


All times are GMT -5. The time now is 07:44 PM.