- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- problem with "sar" command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:11 AM
06-22-2006 12:11 AM
problem with "sar" command
I got a script to generate the alerts if CPU utilization goes over 80%:
#vi cpu_alert.sh
sar -u 1 10 |awk '{print $5}' | if [ "$5" -le 20 ]; then
echo "High CPU Utilization" | mailx -s 'subject' praveen@domain.com
fi
:wq!
#chmod 777 cpu_alert.sh
#./cpu_alert.sh
#
then everytime i am getting a email alert while the cpu utilization is only 2% means idle value is 99%.
this is the output of :
#sar 1 5
HP-UX blkbrd B.11.11 U 9000/800 06/22/06
07:05:43 %usr %sys %wio %idle
07:05:44 0 0 1 99
07:05:45 0 0 0 100
07:05:46 0 0 1 99
07:05:47 0 1 0 99
07:05:48 0 0 2 98
Average 0 0 1 99
why i am getting alert?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:26 AM
06-22-2006 12:26 AM
Re: problem with "sar" command
your pipe to the 'if construct' needs repair:
sar -u 1 10 |awk 'NF==5 && $0 !~
"%" {if ($5+0 <= 20) print $1,"High CPU Utilization"}' | mailx -s 'subject' praveen@domain.com
BTW: I assume this mail gets filled up with more information in your real application...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:29 AM
06-22-2006 12:29 AM
Re: problem with "sar" command
Praveen,
your simple awk command will send the word '%idle' to the shell for comparison against 20. You don't want that.
Try to skip the sar header line with something like:
awk "/idle/{next};{print $5}"
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:29 AM
06-22-2006 12:29 AM
Re: problem with "sar" command
I think it should be like this
sar -u 10 1 | egrep -v "^$|HP|Average|idle" | awk '{print $5}'| while read idleper
do
if [[ "$idleper" -le "20" ]]
then
echo "High CPU Utilization" | mailx -s 'subject' praveen@domain.com
fi
done
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:32 AM
06-22-2006 12:32 AM
Re: problem with "sar" command
With your command, I feel that mail will be sent to user whatever the case may be (even if cpu is not highly used), only thing is that the message High CPU utilisation will be sent if condition of high cpu util is satisfied.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:39 AM
06-22-2006 12:39 AM
Re: problem with "sar" command
Well, several things are amiss. You can't reference $5 outside 'awk'. You are testing for a value that is less than 20 but you want to test for a value that is greater than 80, and, you are passing "down the pipe" every sample rather than looking at the average!
One possible variation is:
sar -u 1 10 | \
if [ `awk '/^Average/ {print $5}'` -gt 80 ]; then
echo "High CPU Utilization" | mailx -s 'subject' praveen@domain.com
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 12:46 AM
06-22-2006 12:46 AM
Re: problem with "sar" command
Ooops! [ENOCOFFEE]! Testing less than or equal 20 is correct since it is *idle*, not a total utilization:
sar -u 1 10 | \
if [ `awk '/^Average/ {print $5}'` -le 20 ]; then
echo "High CPU Utilization" | mailx -s 'subject' praveen@domain.com
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 01:30 AM
06-22-2006 01:30 AM
Re: problem with "sar" command
you are partially correct; I will send a mail with no data when the idle value is not above the threshold. So we should change
sar -u 1 10 |awk 'NF==5 && $0 !~ "%" {if ($5+0 <= 20) print $1,"High CPU Utilization"}' | mailx ...
to
message=$(sar -u 1 10 |awk 'NF==5 && $0 !~ "%" {if ($5+0 <= 20) print $1,"High CPU Utilization"}')
[ -n "$message" ] && print "$message" | mailx ...
mfG Peter