Check script duration

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rodrigofreitas
Posts: 1
Joined: Fri May 25, 2018 5:16 am

Check script duration

Post by rodrigofreitas »

Hi everyone,
I need to run a script running every minute on a Linux machine. My goal is to track how long it takes to complete. Lets say, under 5 seconds, ok, under 15, warning and over 30 critical. Which kind of plugin/script should I use? The ones I find are to check services uptime and stuff like that.

Thanks for the help,
Rodrigo
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check script duration

Post by mcapra »

This is pretty easy to do with a bit of Bash:
https://stackoverflow.com/questions/385 ... -the-shell
https://unix.stackexchange.com/question ... ffectively

Have the script store it's runtime in some temp file via redirection. You could either parse that file's contents in a simple Bash script which returns Nagios-friendly information, or leverage one of the various "file age" plugins to see how frequently that file is written with the idea being that the file is written every time the script runs and the age of the file represents the approximate runtime (minus 60 seconds or whatever the execution interval is):
https://exchange.nagios.org/directory/P ... ck/details
https://github.com/nagios-plugins/nagio ... ile_age.pl

Though for your particular use-case, it is worth mentioning that Nagios Core works off of a 60-second interval by default (interval_length). So catching all of those 15/30 second runtimes is going to require a bit of luck.
Former Nagios employee
https://www.mcapra.com/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Check script duration

Post by scottwilkerson »

thanks @mcapra
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked