Check Windows Process memory

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
JohnFLi
Posts: 559
Joined: Mon Jun 17, 2013 3:11 pm

Re: Check Windows Process memory

Post by JohnFLi »

Ok, I'm almost there.....

my powershell script is:

Code: Select all

param($warn, $crit)
$LastExitCode = 3
$Output1 = ""
$output = ""
$myW3WP = Get-Process w3wp |  Sort -Descending WS| select -first 1 | Measure-Object WS -Sum 
$myW3WP = $myW3WP.sum / 1mb

 
if ($myW3WP -gt $crit)
        {
            $LastExitCode = 2
            $output1 = "CRITICAL: Memory for W3WP has passed 1 gig $myW3WP"
            $output = $output1
            
            
        }
    elseif ($myW3WP -gt $warn)
        {
            $LastExitCode = 1
            $output1 = "WARN: Memory for W3WP is getting close to 1 gig $myW3WP"
            $output = $output1
            
            
        }
    else 
        {
            $LastExitCode = 0
         
           
        }


$output = $output1
Write-Host $output $LastExitCode 
$myW3WP = ""

from the CL on the Nagios server I enter:

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a 200 1000
The response (in the CL) is:

Code: Select all

WARN: Memory for W3WP is getting close to 1 gig 217.83203125 1
yet in XI, it returns this:

Code: Select all

Ok
Cannot convert value "$" to type "System.Double". Error: "Input string was not
in a correct format."

At C:\\scripts\\checkW3WP.ps1:9 char:5

+ if ($myW3WP -gt $crit)

+ ~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (:) [], RuntimeException

+ FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

3
any ideas on that??

Also, what do I need to change so Nagios with also display warning or critical? even with this, it still shows Green
Everybody is somebody else’s weirdo
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Check Windows Process memory

Post by lmiltchev »

This looks good. I would add the following line on the bottom of the script:

Code: Select all

echo $myW3WP
Place the script in the NSClient++ scripts directory, define the check in the "nsclient.ini" file, i.e.

Code: Select all

check_process_memory = cmd /c echo scripts\process_mem.ps1; exit $LastExitCode | powershell.exe -command -
and test it from the CLI on the Nagios XI server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -p 5666 -c check_process_memory
Edit: I didn't realize you made another post on the 2nd page. I was replying to the previous post - sorry about that! Give us some time to test this in house.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
JohnFLi
Posts: 559
Joined: Mon Jun 17, 2013 3:11 pm

Re: Check Windows Process memory

Post by JohnFLi »

any luck?
Everybody is somebody else’s weirdo
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Check Windows Process memory

Post by lmiltchev »

OK. Try the following:

1. Change your script to look like this:

Code: Select all

param($warn, $crit)
    $LastExitCode = 3
    $output = ""
    $myW3WP = Get-Process w3wp |  Sort -Descending WS| select -first 1 | Measure-Object WS -Sum
    $myW3WP = $myW3WP.sum / 1mb


    if ($myW3WP -gt $crit)
            {
                $output = "CRITICAL: Memory for W3WP has passed 1 gig $myW3WP"
                $LastExitCode = 2
			}	
        elseif ($myW3WP -gt $warn)
            {
                $output = "WARN: Memory for W3WP is getting close to 1 gig $myW3WP"
                $LastExitCode = 1
            }
        else
            {
                $output = "OK: Everything seems to be fine $myW3WP"
				$LastExitCode = 0
            }

	Write-Host $output
	exit $LastExitCode
2. Define your command in the nsclient.ini as this:

Code: Select all

check_w3wp = cmd /c echo scripts\check_w3wp.ps1 $ARG1$; exit $LastExitCode | powershell.exe -command -
3. Test your check by running the following command on the Nagios XI box:

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
Let me know if this helped. I am pretty sure this can be improved but this should at least get you started.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
JohnFLi
Posts: 559
Joined: Mon Jun 17, 2013 3:11 pm

Re: Check Windows Process memory

Post by JohnFLi »

I copy and pasted the re-write of the powershell you supplied

in the .ini file

Code: Select all

[/settings/external scripts/scripts]
check_w3wp=cmd /c echo C:\scripts\checkW3WP.ps1 "$ARG1$"; exit $LastExitCode | powershell.exe -command -
from CLI

Code: Select all

 ./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
output:

Code: Select all

CRITICAL: Memory for W3WP has passed 1 gig 240.82421875
so now it thinks 240 > 1000

XI reports the same, but at least it is reporting instead of erroring.


just did a test...when passing the variable to the powershell, its passing 200 1000 into the $warn and nothing into the $crit
Everybody is somebody else’s weirdo
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Check Windows Process memory

Post by lmiltchev »

H-m-m, it works for me as far as I can tell:

Code: Select all

[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '500 1000'
OK: Everything seems to be fine 436.9609375
[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '200 1000'
WARN: Memory for W3WP is getting close to 1 gig 449.60546875
[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '200 300'
CRITICAL: Memory for W3WP has passed 1 gig 448.64453125
Try removing the double quotes from around your arg:

Code: Select all

check_w3wp=cmd /c echo C:\scripts\checkW3WP.ps1 $ARG1$; exit $LastExitCode | powershell.exe -command -
and restart NSClient++ service. Did this help?
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
JohnFLi
Posts: 559
Joined: Mon Jun 17, 2013 3:11 pm

Re: Check Windows Process memory

Post by JohnFLi »

yeah, it's weird..... it's happy at the CLI,
but XI, and core it isn't working right

in CLI

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
OK: Everything seems to be fine 169.0625
in XI:

Code: Select all

Current Status:	  CRITICAL   (for 0d 0h 5m 24s)
Status Information:	CRITICAL: Memory for W3WP has passed 1 gig 169.03515625
You do not have the required permissions to view the files attached to this post.
Everybody is somebody else’s weirdo
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Check Windows Process memory

Post by Box293 »

Can you please post your Nagios XI service definition. In CCM > Monitoring > Services click the icon that looks like a disk and you will get it's text config.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
JohnFLi
Posts: 559
Joined: Mon Jun 17, 2013 3:11 pm

Re: Check Windows Process memory

Post by JohnFLi »

Code: Select all

define service {
	host_name			G1VPFMS02
	service_description		W3WP Memory
	check_command			check_nrpe!check_w3wp!200 1000!!!!!!
	max_check_attempts		5
	check_interval			5
	retry_interval			1
	check_period			xi_timeperiod_24x7
	notification_interval		5
	first_notification_delay	0
	notification_period		xi_timeperiod_24x7
	notification_options		w,c,u,
	contacts			My Name
	register			1
	}	
at CLI

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
OK: Everything seems to be fine 194.9296875
XI display:

Code: Select all

G1VPFMS02View service status details for this host	W3WP MemoryNotifications are disabled for this service	Critical	2d 18h 12m 19s	5/5	01/18/2016 08:08:29	CRITICAL: Memory for W3WP has passed 1 gig 194.94140625
Everybody is somebody else’s weirdo
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Check Windows Process memory

Post by tgriep »

Edit the W3WP Memory service on your XI server
Change your $ARG2$ from

Code: Select all

200 1000
to

Code: Select all

-a '200 1000'
Save it out and apply the config and let us know if this fixes it for you.
The default $ARG2$ for check_nrpe is blank so you you need to fill in the full command line arguments for $ARG2$.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked