Page 1 of 1
Monitor a special windows service
Posted: Tue May 23, 2017 3:42 pm
by moketman
Hello all,
I monitor a windows server, but a service or maybe several, use once a week many memories ans many cpu.
Is it possible to have an alert knowing wich services use lot of memory and cpu ? Is that possible with nsclient++ on the server, or do I need to use another client ?
Thanks to all.
MM
Re: Monitor a special windows service
Posted: Tue May 23, 2017 4:54 pm
by tgriep
Take a look at this powershell script on the Exchange site.
https://exchange.nagios.org/directory/P ... 29/details
It could be what you are looking for.
Re: Monitor a special windows service
Posted: Thu May 25, 2017 3:02 pm
by moketman
Thanks, I will take a look.
Re: Monitor a special windows service
Posted: Thu May 25, 2017 3:14 pm
by dwhitfield
Please be aware that we are closed on Monday due to a US Holiday and close on Fridays early. Thus, if you want a response before Tuesday, you'll need to let us know additional info by tomorrow morning US Central time.
Re: Monitor a special windows service
Posted: Thu Jun 01, 2017 10:08 am
by moketman
Do you have any idea how it works ?
I tried to launch it from the server but it didn't work...
I have entered all the parameters and I don't know how to configure it in Nagios.
Do you have any idea ?
Thanks
MM
Re: Monitor a special windows service
Posted: Thu Jun 01, 2017 10:29 am
by dwhitfield
How what works?
Here are instructions for installing NSClient:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
If you already have it installed, there is a link on the last page of that PDF for actually setting things up.
If you are asking about the powershell script, it's not something we wrote, but it's not a particularly long script. Here's the code:
Code: Select all
# Checks CPU & Memory and reports highest utililzation process if warn/crit
param([string] $servername, [int] $memwarn, [int] $memcrit, [int] $CPUq, [int] $CPUp)
$memalarm = 0
$cpualarm = 0
$alarm = 0
try
{
$TotalRAM = (get-WMIObject win32_operatingsystem -computername $servername | Measure-Object TotalVisibleMemorySize -sum).sum / 1024
$FreeRAM = ((get-WMIObject -computername $servername -class win32_operatingsystem).freephysicalmemory) / 1024
$UsedRAM = (($TotalRAM) - ($FreeRAM))
$RAMPercentUsed = ([math]::truncate(($UsedRAM) / ($TotalRAM) * 100))
if ($RAMPercentUsed -gt $memcrit){
$memhog = (get-process | sort-object WS -descending | select-object -first 1)
$memhogname = ($memhog).processname
$memhogid = ($memhog).Id
$memalarm = 2
$output1 = "CRITICAL: Memory is $RAMPercentUsed% used. $memhogname is using the most resources, its PID is $memhogid. | Memory=$RAMPercentUsed%;;;0"
}
elseif ($RAMPercentUsed -gt $memwarn){
$memhog = (get-process -computername $servername | sort-object WS -descending | select-object -first 1)
$memhogname = ($memhog).processname
$memhogid = ($memhog).Id
$memalarm = 1
$output1 = "WARN: Memory is $RAMPercentUsed% used. $memhogname is using the most resources, its PID is $memhogid. | Memory=$RAMPercentUsed%;;;0; "
}
$CPUQueue = (Get-WmiObject -computername shares Win32_PerfRawData_PerfOS_System).ProcessorQueueLength
$CPUpercent = (Get-WmiObject -computername $servername win32_processor | Measure-Object -property LoadPercentage -Average).Average
if (($CPUQueue -gt $CPUq) -and ($CPUpercent -gt $CPUp)){
$cpuhog = (get-process -computername $servername | sort-object CPU -descending | select-object -first 1)
$cpuhogname = ($cpuhog).processname
$cpuhogid = ($cpuhog).Id
$cpualarm = 2
$output2 = "CRITICAL: CPU Queue = $CPUQueue CPU% = $CPUpercent. $cpuhogname is using the most resources, its PID is $cpuhogid | CPU=$CPUpercent%;;;0; CPU Queue=$CPUQueue;;;0; "
}
$alarm = $cpualarm + $memalarm
$output = $output1 + $output2
if ($alarm -ge 2){
write-host $output
exit 2
}
Elseif ($alarm -eq 1) {
write-host $output
exit 1
}
else {
write-host "OK: Memory is $RAMPercentUsed % used, CPU % is $CPUpercent and CPU Queue is $CPUQueue | Memory=$RAMPercentUsed%;;;0; CPU=$CPUpercent%;;;0; CPU Queue=$CPUQueue;;;0;"
exit 0
}
}
catch
{
Write-Output $_;
$_="";
exit 3;
}
Would you prefer something in a different language? The only problem with say, a python script is then you need to install python on Windows. That's certainly not impossible, but it is an extra step.