Question : AIX cpu alarm monitor script.

I'm looking for a script that uses vmstat from cron on like a minute interval to capture processes that utilize 95%+ cpu load. I then need the minute outputs processed so that if any process is consuming more then 95% cpu time for over a period of let's say 10 minutes, only then a single warning email gets sent to me about those processes.

Thanks in advance.

Answer : AIX cpu alarm monitor script.

Ok, here's a script. But remember "vmstat" doesn't show process level stats so we're using "ps". Now the "%CPU" that "vmstat" reports is cpu use over the lifetime of that process - so an old process that starts to use 100% will not get caught for a while. To be more robust you will need additional tools, like "top".
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
#!/bin/ksh
 
MONITOR_FILE=/tmp/monitor.lst
 
ps -aeF"pid=,pcpu=" | while read PID PCPU
do
        if [[ -n "$PCPU" && "$PCPU" -gt 0.95 ]]
        then
                echo $PID >>$MONITOR_FILE
        fi
done
 
cat $MONITOR_FILE | sort | uniq -c | while read HOWMANY PID
do
        if [[ "$HOWMANY" -gt 10 ]]
        then
                echo $PID
        fi
done | mail -s "PIDs Running >95%" user@system.com
Open in New Window Select All
Random Solutions  
 
programming4us programming4us