Check CPU usage in seconds

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
bostjanc
Posts: 17
Joined: Mon Mar 21, 2016 11:12 am

Check CPU usage in seconds

Post by bostjanc »

Hi guys.
Do you think it could be possible to monitor Windows process with nagios in scenario where you wish to get an alarm when process.exe consumes 50% of CPU more then 10 seconds.
Or when process consumes 3GB of memory more then n-seconds?
Any ideas how to achieve that?
with best regards
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check CPU usage in seconds

Post by rkennedy »

While it's possible, I wouldn't recommend it. Based on what you mention here, you'll be checking the Windows machine every few seconds, which I'd advise against for many reasons.

You could create a plugin, that runs a check for you over the CLI, and then stores that information. Now, have it wait x seconds, and execute the same check again. Have your plugin compare the results, and output them to Nagios. You would most likely need to write this yourself, or see if you can find something that works for you on our exchange @ https://exchange.nagios.org.
Former Nagios Employee
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Check CPU usage in seconds

Post by bwallace »

I agree with rkennedy - I would not encourage any check to occur every few seconds or so, either. In fact, one minute is the smallest check frequency Nagios is capable of conducting.

The Nagios XI Windows server wizard enables you to set thresholds for memory, CPU, etc but does not allow for what you're talking about - if process abc.exe is using 50% CPU for a sustained 10 seconds.

I did a quick check at our exchange site for a plugin containing this functionality and did not find anything. You can have a look to see if I missed something, but I suspect you'd have to write this yourself, as rkennedy mentioned.
https://exchange.nagios.org/index.php?o ... 0processes
Be sure to check out the Knowledgebase for helpful articles and solutions!
User avatar
nozlaf
Posts: 172
Joined: Sun Nov 09, 2014 9:50 pm
Location: Victoria, Australia

Re: Check CPU usage in seconds

Post by nozlaf »

as an alternative you could just trigger if CPU exceeded threshold then return the process list with the memory and cpu time in the list
if you look at the nsclient documentation and do a little massaging you should be able to get it to work

Code: Select all

https://docs.nsclient.org/reference/windows/CheckSystem.html#check-process
for the memory threshold you certainly can trigger if the process has exceeded the memory limit also included in the previous link
Looking forward to seeing you all at #NagiosCon2019?
-Dedicated Lover of Nconf,PNP4Nagios and Nagvis
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check CPU usage in seconds

Post by rkennedy »

To add to what @nozlaf mentioned, could always log the top mem / cpu processes locally as well. I wrote a few scripts you could use to do so here -
https://support.nagios.com/forum/viewto ... 39#p167539
Former Nagios Employee
Locked