Linux

check_proc_age.sh

Description:

this bash script check if processes matching to a pattern are exceeding a given elapsed time.

Current Version

1.2

Last Release Date

2012-04-24

Compatible With

  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
  • Nagios XI
  • Nagios Fusion

Owner

License

GPL


Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Project Files
Project Notes
This Nagios plugin check if processes matching to a pattern are exceeding a given elapsed time Usage : check_proc_age.sh -p -w -c -p parameter : name of the monitoring process -c parameter : minimal elapsed time for status CRITICAL on NAGIOS -w parameter : minimal elapsed time for status WARNING on NAGIOS the plugin return now performance data : number of process; oldest time in minutes; warning time in minutes; critical time in minutes; 0; this is a improvement of "check_proc_time.sh" plugin. The output text of my plugin is more clear about processes state and "check_proc_time.sh" calculate a bad elapsed time in certain case on my system.
Reviews (4) Add a Review
Needs small update
by banditbbs, December 31, 2017
The if (td[2]) in the ageproc line needs updated. It needs to be if ("td[2]") to test if empty or not. Necause if the time happens to be 123-00:40:23 the if would be false when it actually contains 00.
Helpful? Yes  No 
Find full process
by LaFong, May 31, 2017
This plugin does not find processes in the format 'interpreter /path/to/script', i.e. 'perl /usr/local/sbin/myscript.pl'. I also wanted to be able to just specify, in this case, 'myscript.pl'. My changes to add those:

@@ -70,12 +70,12 @@
fi

#calculate number of process
-nbproc=$(ps -A -o comm | grep -w $proc | grep -v $0 | wc -l)
+nbproc=$(ps -A -o args | grep -w "$proc" | grep -v $0 | grep -v grep | wc -l)
if [ $nbproc -gt 0 ]
then

#calculate age of oldest process
- ageproc=$(ps -A -o etime,comm,args | grep $proc | grep -v $0 | gawk '{split($1,t,":");split(t[1],td,"-");if (td[2]) {ta=td[1]*86400; t[1]=td[2]} else {ta=0}; if (t[3]) {$1=(t[1]*60+t[2])*60+t[3]+ta} else {$1=t[1]*60+t[2]};if (NR==1) {maxi=$1;} else {if ($1>maxi){maxi=$1;}}};END {print maxi}')
+ ageproc=$(ps -A -o etime,comm,args | grep "$proc" | grep -v $0 | grep -v grep | gawk '{split($1,t,":");split(t[1],td,"-");if (td[2]) {ta=td[1]*86400; t[1]=td[2]} else {ta=0}; if (t[3]) {$1=(t[1]*60+t[2])*60+t[3]+ta} else {$1=t[1]*60+t[2]};if (NR==1) {maxi=$1;} else {if ($1>maxi){maxi=$1;}}};END {print maxi}')
case $ageproc in
?|[0-5]? ) maxage=$ageproc" Seconds";;
Helpful? Yes  No 
Improvement
by neozaga, January 31, 2017
Hi,

Made this improvment

line 73:
nbproc=$(ps -A -o cmd | grep -w $proc | grep -v grep | grep -v $0 | wc -l)

so that you can search the full command line and not to find itself. (I know grep -v grep is ugly)
Helpful? Yes  No 
Bug + minor improvements
by formwandler, April 30, 2012
1) Line 86 has a bug

Original:
elif [$ageproc -gt $warning ]

Corrected:
elif [ $ageproc -gt $warning ]

2) Minor improvements I made

a) nbproc

The "comm,args" options should be changed to "comm" only, otherwise the calculated number of processes is always increased by 1.

nbproc=$(ps -A -o comm | grep -w $proc | grep -v $0 | wc -l)

b) Output

The output should always begin with w.g. "CRITICAL: ", "WARNING: " or "OK: ".
Owner's Reply:

Thanks for the advices, my script has been updated.


2 of 2 found this review helpful.
Helpful? Yes 2 No 0
Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4 (6)
Favorites
1
Views
87,727