0

I'm look for shell script to send Top processes as an email when Monitor CPU load average exceed 20 I'm running RedHat 6.

user105196
  • 69
  • 1
  • 5
  • http://serverfault.com/questions/318588/nagios-plugin-to-take-process-snapshot-when-load-is-high – quanta Feb 26 '13 at 07:43

1 Answers1

2
uptime | awk '$NF >= 20 { system("top -cSb n 1") }' \
    | tail -n +8 | sort -rn -k11 | head \
        | mail -s "PROBLEM Service Alert: load_fifteen is CRITICAL" email@domain
  • NF stands for Number of Fields. $NF get the value of the last field. This is the system load average for past 15 minutes
  • top -b to run in batch mode, for sending output to stdout
  • tail -n +8 | sort -rn -k11 | head: remove the headers, then sort by CPU Time, and get the top processes.
quanta
  • 51,413
  • 19
  • 159
  • 217