LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2013, 11:46 AM   #1
aigberay
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Rep: Reputation: Disabled
email when unix system CPU usage is above 70%


Hey Colleagues;
I need to write a shell script that will send me an email when unix system CPU usage is bove 70% threshold, will really appreciate your response as i equally put it together from my end.
 
Old 10-17-2013, 12:30 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,481

Rep: Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089
70% of one processor usage? 70% of all procs? Do you include hyper-threading virtual procs in this count? 70% instantaneous or time-averaged? Over what length of time? When the limit is exceeded, how do you want to handle emails. Every minute while it's over the limit? Every 5 minutes? Once when it passes the limit and not again until it drops back below for at least XX minutes, then rises back above?

Last edited by suicidaleggroll; 10-17-2013 at 12:31 PM.
 
Old 10-17-2013, 03:29 PM   #3
aigberay
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
When 70% of all processes, an email should be sent to a specified email id with a subject "WARNING CPU USAGE HIGH"
 
Old 10-17-2013, 03:35 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,481

Rep: Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089
That answered one of the five questions that were asked.

You can't expect to tackle a problem (or have somebody else tackle the problem for you) if you can't define it properly.
 
Old 10-17-2013, 06:06 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by aigberay View Post
I need to write a shell script
Show us what you've got already then.
 
Old 10-18-2013, 10:30 AM   #6
aigberay
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Let me be more explicit

I intend to explain in details what i really want so i can get suport easily from you guys, i want a script that can monitor CPU usage of unix system so that if the CPU usage is more than 70% your script will send out email saying that CPU is more than threshold of 70%. I created the below script but it did send a warning email but the percentage was wrong when compared to the result when i use the "top" command.
#!/bin/sh
#Date = 10/18/2013
#Set the alarm threshold here
#Set to 70 to make it send notifications if average utilization goes past 70%
THRESHOLD=70

MAILTO="meray@company.com"
#The temp file below will be replaced everytime this script runs
TEMPFILE=/tmp/cpu.temp

#
#LOGIC BLOCK:
#

HOSTNAME=`isbinf03`
rm -f $TEMPFILE

#Calculate the CPU Utilization with the command below
#Note: this command will calculate the avg CPU utilization of last 10 secs
CPU=$(vmstat 10 2 | tail -1 | awk '{print $15}' | sed 's/%//')
let "CPU = 100 - $CPU"
#echo "`date` - CPU Utilization: $CPU"

#Compare the current value with the threshold one.
if [ $(expr $CPU ">=" $THRESHOLD) -ne 0 ]
then
echo "Warning - CPU utilization on server $HOSTNAME is ${CPU}%" >> $TEMPFILE
fi

#Send an email if /tmp/cpu.temp is present.
if [ -e $TEMPFILE ]
then
mail -s "$HOSTNAME CPU Warning" $MAILTO < $TEMPFILE
fi

rm -f $TEMPFILE
once again i will appreciate your help.
 
Old 10-19-2013, 05:06 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
It would help if you read http://en.wikipedia.org/wiki/Load_%28computing%29 as it shows you how to calculate CPU usage like you should?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Calculating CPU-Usage for Unix/Linux..? mrm5102 Linux - Newbie 7 03-08-2012 03:16 PM
[SOLVED] diagnosing heavy cpu system usage andrews-mark Linux - General 3 10-24-2011 03:48 PM
High system CPU usage Uruclef Linux - Server 2 04-12-2011 09:56 AM
LXer: Measuring Heavy CPU Usage Over Time On Linux And Unix LXer Syndicated Linux News 0 03-31-2009 07:00 AM
Why do I have a High System CPU Usage Bottleneck linuxboy69 Linux - Software 3 09-02-2004 03:55 PM


All times are GMT -5. The time now is 02:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration