Skip to content

Commit 030a750

Browse files
author
Michael Jennings
committed
Add some improved annotation and debugging to the resource checks.
1 parent 4a1f27b commit 030a750

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

scripts/ww_ps.nhc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ function nhc_ps_check_res() {
192192
nhc_common_get_userid $OWNER OWNER
193193
fi
194194

195+
dbg "Looking for processes matching \"$MATCH\"${OWNER:+ owned by ${OWNER}}"
195196
for ((i=0; i < ${#PS_PROCS[*]}; i++)); do
196197
THIS_PID=${PS_PROCS[$i]}
197198
if [[ $FULLMATCH == 1 ]]; then
@@ -220,6 +221,7 @@ function nhc_ps_check_res() {
220221
fi
221222
fi
222223
# We have a matching process with the correct owner. Now check resource consumption.
224+
dbg "Matching process found: $THIS_PROG[$THIS_PID]: ${PS_PCPU[$THIS_PID]}% CPU, ${PS_PMEM[$THIS_PID]}% (${PS_RSS[$THIS_PID]}kB) RAM, ${PS_VSZ[$THIS_PID]}kB mem, ${PS_TIME[$THIS_PID]} time"
223225
case $COL in
224226
1) if [[ ${PS_PCPU[$THIS_PID]%%.*} -lt $THRESHOLD ]]; then continue ; fi
225227
MSG="$CHECK: Process \"$THIS_PROG\" ($THIS_PID) using ${PS_PCPU[$THIS_PID]}% CPU (limit $THRESHOLD%)"
@@ -233,7 +235,7 @@ function nhc_ps_check_res() {
233235
MSG="$CHECK: Process \"$THIS_PROG\" ($THIS_PID) using $NUM RAM (limit $LIM)"
234236
;;
235237
4) if [[ ${PS_VSZ[$THIS_PID]} -lt $THRESHOLD ]]; then continue ; fi
236-
nhc_common_unparse_size ${PS_RSS[$THIS_PID]} NUM
238+
nhc_common_unparse_size ${PS_VSZ[$THIS_PID]} NUM
237239
nhc_common_unparse_size $THRESHOLD LIM
238240
MSG="$CHECK: Process \"$THIS_PROG\" ($THIS_PID) using $NUM memory (RAM+swap) (limit $LIM)"
239241
;;
@@ -286,7 +288,8 @@ function nhc_ps_check_res() {
286288
die 1 "$MSG"
287289
return 1
288290
done
289-
# -a (all) does not necessarily imply -0 (non-fatal)
291+
# -a (all) does not necessarily imply -0 (non-fatal). A value of 1 for $ALL
292+
# means -a was passed in but no errors were found. 2 or above is an error.
290293
if [[ $ALL -gt 1 ]]; then
291294
# We had at least 1 flagged process. Fail unless we're also non-fatal.
292295
if [[ $NONFATAL == 1 ]]; then
@@ -295,8 +298,9 @@ function nhc_ps_check_res() {
295298
fi
296299
return 0
297300
fi
298-
die 1 "$MSG ($((ALL-1)) of $((ALL-1)))"
299-
return $((--ALL))
301+
((ALL--))
302+
die $ALL "$MSG (last of $ALL)"
303+
return $ALL
300304
fi
301305
return 0
302306
}

0 commit comments

Comments
 (0)