-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
check_proc_zombie 1.86 KiB
#!/bin/bash
# ======================================================================
#
# Check for zombie processes
#
# requirements:
# - top
#
# ----------------------------------------------------------------------
# 2020-03-10 v1.0 <axel.hahn@iml.unibe.ch>
# 2020-07-08 v1.1 <axel.hahn@iml.unibe.ch> FIX: set "ph." instead "ps."
# ======================================================================
. `dirname $0`/inc_pluginfunctions
tmpfile=/tmp/check_proc_zombie_$$
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check required tools
ph.require top
# --- check param -h
if [ "$1" = "-h" ]; then
echo "
usage: $0 [ -w value -c value -h ]
-w Warning level
-c Critical level
-h this help
"
exit 0
fi
# set default / override from command line params
typeset -i iWarnLimit=` ph.getValueWithParam 1 w "$@"`
typeset -i iCriticalLimit=` ph.getValueWithParam 10 c "$@"`
# get cpu status i.e.
# %Cpu(s): 33.3 us, 9.5 sy, 0.0 ni, 57.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
top -b -n 1 | head -5 | grep "^Tasks:" >$tmpfile
iProcTotal=` awk '{ print $2 }' $tmpfile`
iProcRunning=` awk '{ print $4 }' $tmpfile`
iProcSleeping=`awk '{ print $6 }' $tmpfile`
iProcStopped=` awk '{ print $8 }' $tmpfile`
iProcZombie=` awk '{ print $10 }' $tmpfile`
rm -f $tmpfile
ph.setStatusByLimit ${iProcZombie} ${iWarnLimit} ${iCriticalLimit}
# --- status output
ph.status "${iProcZombie} ZOMBIE-Processes (total: ${iProcTotal} - running: ${iProcRunning} - sleeping: ${iProcSleeping} - stopped: ${iProcStopped})"
ps -efl | grep -i "^[0-9]* Z"
# --- performance data usage
ph.perfadd "proc-zombie" "${iProcZombie}" $iWarnLimit $iCriticalLimit 0
# --- Bye
ph.exit
# ----------------------------------------------------------------------