Memory_Monitor

Dear All

 

Following script can be scheduled on server to run after every 5 minutes which will monitor the free RAM on server and if RAM free RAM goes below 256mb then it wll send email.

 

dim str,mess
str="."
Check_Available_Virtual_Memory str,256

Function Check_Available_Virtual_Memory(strComputer,strThresholdMB)
dim wbemServices,wbemObjectSet,wbemObject,AvailableVMB,strStatus
Check_Available_Virtual_Memory=false
EXPLANATION = "Failed, error getting values."

Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("CIM_OperatingSystem")

For Each wbemObject In wbemObjectSet
AvailableVMB=int(wbemObject.FreePhysicalMemory/1024)
strStatus="Available Physical Memory=" & AvailableVMB & "mb, Threshold=" & strThresholdMB & "mb"

if AvailableVMB > strThresholdMB then
Check_Available_Virtual_Memory=true
EXPLANATION = "Success, " & strStatus
else
Check_Available_Virtual_Memory=false

EXPLANATION = "Failure, " & strStatus

dim j, NIC1, Nic, StrNic, lngCount, StrIP, i ,objNet,objHost
‘If something fails, move on
On Error Resume Next
‘Get the Computer’s network name
Set objNet=CreateObject("wscript.Network")
objHost=objNet.ComputerName
‘Wscript.Echo "Analysis of " & objHost & "."

‘Get a connection to the WMI NetAdapteConfig object
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")

‘For Each of the NICs in the connection
dim ip
ip=""
For Each Nic in NIC1
   ‘Get the Adapter Description
   StrNIC = Nic.Description
     ‘If IP is enabled on the NIC then let’s find out about the NIC
     IF Nic.IPEnabled THEN
        lngCount=UBound(Nic.IPAddress)
        For i=0 to lngCount
           If i >= 0 Then
           StrIP = vbTab & Nic.IPAddress(i)
           If StrIP <> "" Then

if ip<>"" then
ip=ip+" | "+  StrIP
else
    ip=   StrIP
end if
                  End If
              End If
            Next
          END IF
      Next
mess="Hi , Please check that the server ip :-"+ ip + " | The availabe RAM is less than 256 mb only , Current Memory Status is : – "+ StrStatus
SendMail "prashantd@mkcl.org", "prashantd@mkcl.org " , "Physical Memory Alert (RAM)"  , Mess

end if
Next
end function
wscript.quit

Sub SendMail(Sender, Recipient, Subject, Message)

Const MailServer = "127.0.0.1" ‘ Mail Server to use (SMTP)
Const MailServerPort = "25" ‘ SMTP Port used at Mail server (25 is default)

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Subject
objMessage.From = Sender
objMessage.To = Recipient
objMessage.TextBody = Message

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailServer

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailServerPort

objMessage.Configuration.Fields.Update

objMessage.Send
End Sub

 

Thanks

 

Prashant Deshpande

 

Advertisements

Leave a comment

Filed under ServerMonitoring

Comments are closed.