CPU usage for 5 mins


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers CPU usage for 5 mins
# 1  
Old 04-15-2013
RedHat CPU usage for 5 mins

Hi Experts,

Please help me in find the right way to create a script for the below task.

Task - I need to create a alert script for CPU usage and I only need to alert when there is a process hold the CPU high for more than 5 mins.

Initially five mins one use the ps command five mins once like below to get the high CPU usage

Code:
ps -eo pcpu | sort -nr | head -1 | awk '{print int($1)}'


But the problem is this script will also alert the process which momentary spike and come to normal. So i am using the line below to calculate the idle CPU then the process count. Is there any better way to deal this, please help me with your ideas?

Code:
sar -u 12 20 | tail -1 | awk '{print int($8)}'

Its a red hat Linux machine
# 2  
Old 04-15-2013
Take three cpu readings, separated by five minutes sleep.

If reading is normal, set a log file (that you maintain) to zero.
If reading is high, increment the count in the log file.
If reading if high, and log file count is three, take action.

This way, you rule out a temporary spike.
# 3  
Old 04-15-2013
if i do so i will get alert after 15 min about a CPU high do any simple way to perform.

Thanks
# 4  
Old 04-15-2013
Yes, you would get an alert after 15 minutes, if that is the question.

If 15 minutes is too long, you could sleep less than five minutes. Or maybe use "load average" from uptime.
This User Gave Thanks to hanson44 For This Post:
# 5  
Old 04-15-2013
what is the best way to read the CPU? you mentioned in your earlier reply we need to for three readings so shall i use like below. appriciate your comments

Code:
mpstat 5 3 | tail -1 | awk '{print int($10)}'

Code:
sar 5 3 | tail -1 | awk '{print int($8)}'

# 6  
Old 04-15-2013
I'm not sure the best way to read cpu. I normally use uptime "load average". If there is one process going constantly on a single cpu system, the load average is 1. You would need to decide how high a load to tolerate, based on the normal load you see.
Code:
$ uptime
 14:56:02 up 69 days, 15:00,  1 user,  load average: 0.08, 0.02, 0.01
$ uptime | sed "s/.*load average: *\([0-9]*\).*/\1/"
0

Code:
load=`uptime | sed "s/.*load average: *\([0-9]*\).*/\1/"`
if [ $load -gt 0 ]; then
  # figure out if load was high previous two times
  # if previously high two times, send email message and maybe exit script.
  # otherwise, record that load was high, and continue loop, to sleep a while.
else
  # record that load was normal
fi

On my linux system, sar and mpstat are not installed, but they should work fine too, since they measure cpu usage. It would just be a matter of using sed or awk to get the right number from the sar or mpstat output.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

2. Windows & DOS: Issues & Discussions

CPU usage

Hi all, Top command is used to monitor CPU usage in unix,solaris etc..likewise is there any command in windows environment? Regards William (3 Replies)
Discussion started by: William1482
3 Replies

3. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

4. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

5. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

6. Programming

Cpu usage

Hi all, When I have a below while loop in my code (This observation is same for C and Perl) i= 0; while(1) { i++; } for above the CPU uses goes beyond 49% on hp-ux machine, why cpu usage increase at this level for just a simple while loop? and if I have a single print statement... (2 Replies)
Discussion started by: zing_foru
2 Replies

7. UNIX for Dummies Questions & Answers

CPU usage

can anyone tell me How to check memory and CPU usage of a certain process (1 Reply)
Discussion started by: ccp
1 Replies

8. Programming

CPU usage and memory usage

Please tell me solaris functions/api for getting following information 1- Function that tells how much memory used by current process 2- Function that tells how much memory used by all running processes 3- Function that tells how much CPU is used by current process 4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

9. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies

10. Filesystems, Disks and Memory

cpu usage

hi, In response to your cpu usage answer I too read sys/sysinfo.h but , if we put these values to access the repective time fields in the array pst_cpu_time which is a member of the structure pst_dynamic values doesn't seem to match, why is like this? (0 Replies)
Discussion started by: sushaga
0 Replies
Login or Register to Ask a Question