Technical Article

PowerShell 3rd Party tool Memory Alert

,

We use a 3rd party tool to monitor some SQL Servers on our farm. After an upgrade we had a memory issue( leak ) on one of the nodes. Once the memory usage crosses 90% you can not re start the service seems the server needs a rebooting not an acceptable solution. If you just bounce the services prior to the 90% mark things stay fine and he product continues working as expected. We developed this as a temporary band aid until the bug fix is sent and applied. This is scheduled from Windows task scheduler. I hope someone may be able to make use of the alert.

$hostname = hostname
$os = Get-Ciminstance Win32_OperatingSystem
$pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2)
 write-host "Memory Percent free: $pctFree on $hostname"
if ($pctFree -le 20) {
Restart-Service -Name "SomeCollectionService`$Default" -force
Restart-Service -Name "SomeManagementService`$Default" -force
write-host "Alert memory percent is high" -Fore Red
$strTo = "someone1@somewhere.com,someone2@somewhere.com"
$strFrom = "$hostname@somewhere.com"
$strSubject = "Idera Memory Alert on $hostname"
$strBody = "Idera Services were recycled on: $hostname the memory percent free is: $pctFree"
$objMessage = New-Object System.Net.Mail.MailMessage –ArgumentList $strFrom, $strTo, $strSubject, $strBody

# Define the SMTP server
$strSMTPServer = "SMTP_ServerHere"
$objSMTP = New-Object System.Net.Mail.SMTPClient –ArgumentList $strSMTPServer

# Send the message
$objSMTP.Send($objMessage)
}
 

#Schedule from Win task Scheduler: PowerShell –File "C:\Scripts\Hello.ps1"

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating