Skip to main content
Solved

Process CPU & RAM used

  • 28 May 2024
  • 1 reply
  • 57 views

Hello everyone,

I would need to have the CPU and memory used of a specific process and be able to issue alerts if it exceeds a certain threshold.
I use Centreon NRPE agent for Windows. 

I really apreciate if you have any solution or suggestion.

Regards. 

1 reply

Userlevel 5
Badge +14

Hello

There no out of the box solution for this in NSclient

I think you could try and look at the NSClient parameter with the check “check_process”

CheckSystem (Windows) - NSClient++

you can apparently get the “working set” (memory), but I don’t think you can get a specific cpu usage

 

I think in your case you could code simple powershell scripts to get these information and call them

there is no easy way to do this, you would need a “command” declared in the nsclient.ini 

the powershell should return the value as any check script (with the return  code for the status, the text line, etc… as stated here Plugins development guidelines | Centreon Documentation )

 

in the “[/settings/external scripts/scripts]” section you could add a command

check_cpu_process=powershell -nologo -Noninteractive -ExecutionPolicy RemoteSigned -File scripts\\check_cpu_process.ps1  %ARGS%

all the arguments you will pass to the check_nrpe -a option, exemple --commandc=check_cpu_process --arg=’ -process myprocess.exe’ --arg=’ -warning 80’ --arg=’ -critical 90’

will be passed to powershell in the “%args%”. it is your job to code that in the powershell script to get the correct values and parameters in the script, do the query for the cpu, compute the status ok/warn/crit and return the correct values

 

here is what I use in my PS scripts to be sure to get the correct output code : 

$retText = "UNKNOWN"
$retcode = 3
function checkExit() {Write-host -nonewline $rettext ; exit $retcode }

then I set the retText with the text, the retCode with the correct code 0/1/2/3 and call “checkExit”

 

if this work, the next step is to create a centreon command with the parameters you need, then a “service template” where you can set the process name, warning, critical value, and use that. 

the command would look like that

-arg=’ -process “$_SERVICEPROCESSNAME”’ --arg=’ -warning $_SERVICEWARNING$’ --arg=’ -critical $_SERVICECRITICAL’

(if you use powershell positionnal parameter so the parameters are always in the same order, you could simply do

-arg=’“$_SERVICEPROCESSNAME”’ --arg=’$_SERVICEWARNING$’ --arg=’$_SERVICECRITICAL’ )

 

here is what I use for simple 3 params in my scripts :

PARAM(
[String]$Name="xxx",
[alias("w")][Int32]$warning=80,
[alias("c")][Int32]$critical=90
)

this will  use 3 parameters with default values and aliases

it will allow me to say 

myscript.ps1 abc 80 90 

or myscript.ps1 -Name abc -w 50 -critical 60

 

(on a special note, there are no easy way to get a specific process %cpu usage, you need to query some specific perfcounter, here is an example for the process explorer.exe

(Get-Counter '\Process(explorer)\% Processor Time').countersamples.cookedvalue

this only work with a single process, if you have more process running with the same name, you would need to make a loop and manage multiple values)

for the memory usage “get-process -name explorer” will return usable data in MB directly, but the cpu is the usage in seconds, not %, that’s also why the nsclient software is not returning the %cpu usage, but if you really need it, have fun programming a little custom check)

 

Reply