Page 1 of 2

Need to capture cpu utilization with top process

Posted: Thu May 20, 2021 6:38 am
by lanxessinfy
Hi Team,
Need to capture cpu utilization with top process consuming load for windows server
Currently the we are monitoring the load average using nsclient agent , please let us know if plugins any to capture above metrics for windows system.

Re: Need to capture cpu utilization with top process

Posted: Thu May 20, 2021 3:19 pm
by vtrac
Hi,
How are you doing?

Please check Nagios Exchange page below, I'm sure you will find one that will fit your needs.
https://exchange.nagios.org/

Another solution you could try is to write a PowerShell script (below), then call its using "check_nrpe", since you already have NSClient++ installed on those remote machines.
I'm not a PS programmer, so this is what I found on the web which will list top 5 CPU

Code: Select all

Get-Process | Sort -Descending CPU | Select -First 5
Get-Process gives the amount of processor time that the process has used on all processors


Best Regards,
Vinh

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 03, 2021 6:26 am
by lanxessinfy
Hi Team,

Is there any possible to call this command(Get-Process | Sort -Descending CPU | Select -First 5) when CPU load is more than 80%..

Thanks in advance.

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 03, 2021 1:22 pm
by vtrac
Hi,
How are you doing?
You might have to write a PowerShell script to do that.
Here's an example, please NOTE you will have to modify this as I am NOT a PowerShell programmer:

Code: Select all

Try {
    $Threshold = 79
    $CpuLoad = (Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average ).Average
    IF($CpuLoad -gt $Threshold) {
        Write-Output (Get-Process | Sort -Descending CPU | Select -First 5 | Format-Table -HideTableHeaders)
    } Else {      
        Write-Host "CPU load is" $CpuLoad "%"
    }
}
Catch {
        Write-Host  "Script Check Failed"
}

Best Regards,
Vinh

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 17, 2021 3:30 am
by lanxessinfy
Hi,

could you please let us know how to call above script.

thanks in advance.

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 17, 2021 11:39 am
by vtrac
Hi,
How are you doing?

Since I am assuming you will be calling this using the "check_nrpe" with your NSClient already installed.

Please follow the KB below I found on the web:
https://docs.nsclient.org/howto/external_scripts/


Best Regards,
Vinh

Re: Need to capture cpu utilization with top process

Posted: Fri Jun 18, 2021 12:48 pm
by lanxessinfy
Hi I have Created the file with above command as ProcessMonitoring.ps1 in Scripts folder and have Called in
Nsclient.ini as ProcessMonitoring=cscript.exe //T:30 //NoLogo scripts\\ProcessMonitoring.ps1 $ARG1

But when I test this I'm getting this.

[root@xxxxxxxxx libexec]# ./check_nrpe -H xx.xx.xx.xx -2 -t 30 -c ProcessMonitoring
Input Error: There is no script engine for file extension ".ps1".

Re: Need to capture cpu utilization with top process

Posted: Fri Jun 18, 2021 2:17 pm
by vtrac
Hi,
How are you doing?
Please make sure you have PowerShell installed.

Also, please add your script under the section called below inside the "nsclient.ini" file:

Code: Select all

[/settings/external scripts/scripts]
Once done edit the "nsclient.ini" file, please restart NSClient++ services agent.

Code: Select all

net stop nscp
net start nscp
Example:

Code: Select all

[/settings/external scripts/scripts]
restart_service = scripts\restart_service.bat "$ARG1$"
check_windows_time = scripts\check_windows_time.bat $ARG1$

Best Regards,
Vinh

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 24, 2021 2:36 am
by lanxessinfy
HI Vinh

Thanks much.
we are now able to get the output. The mistake was the last line in nsclient.ini
ProcessMonitoring = cmd /c echo scripts\\ProcessMonitoring.ps1 $ARG1$ "$ARG2$"; exit($lastexitcode) | powershell.exe -command -


Could you please let me know what is the average time here? and can we set average time?

Re: Need to capture cpu utilization with top process

Posted: Thu Jun 24, 2021 10:54 am
by vtrac
Hi,
How are you doing?
I'm sorry, but I am not sure I understand what you meant by "average time".

I thought this ticket was to get CPU utilization with top processes.


Best Regards,
Vinh