Skip to content

Commit ec0eefd

Browse files
committed
Get process age metric
1 parent 9384353 commit ec0eefd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

process_mon.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646
# return new AlarmStatus(CRITICAL, 'Process not running.');
4747
# }
4848
#
49+
# if (metric['process_age'] > 86400) {
50+
# return new AlarmStatus(WARNING, 'Process has been running for over 24 hours.');
51+
# }
52+
#
4953
# return new AlarmStatus(OK, 'Process running normally.');
5054

5155
function help {
5256

5357
cat <<HELP
5458
55-
SYNOPSIS: ./process_mon.sh [process]...
59+
SYNOPSIS: ./process_mon.sh [process]...
5660
USAGE EXAMPLE: ./process_mon.sh lsync
5761
5862
HELP
@@ -64,4 +68,14 @@ if [ -z "$1" ]; then
6468
fi
6569

6670
process_check=`ps ax | grep -v grep | grep -v process_mon | grep -c "$1"`
71+
process_pid=`ps ax | grep -v grep | grep -v process_mon | grep "$1" | head -n 1 | awk '{print $1}'`
72+
if (( $process_check > 0 )); then
73+
process_age=`ps -o etimes= -p "$process_pid"`
74+
process_age=${process_age## }
75+
fi
76+
6777
echo "metric process_mon int $process_check"
78+
echo "metric process_pid int ${process_pid:-0}"
79+
echo "metric process_age int ${process_age:-0}"
80+
81+
exit 0

0 commit comments

Comments
 (0)