Announcement

Collapse
No announcement yet.

Help in creating script to monitor exe memory utilization on server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help in creating script to monitor exe memory utilization on server

    Hi,

    I want to monitor the memory utilization of specific exe "EWBIC.exe" on one of my Windows 2003 server and need to restart the respective service "IC Service" if the specific EWBIC.exe memory utiliztion is 500MB and above

    I want to get any alert / email when any of this happen by running a script after every 10 mints on the server.

    Thanks & Regards
    Dinesh Cholekkavil

  • #2
    Re: Help in creating script to monitor exe memory utilization on server

    Use WMI. Win32_process might be a good starting point. An example at Guy Thomas'.

    -vP

    Comment


    • #3
      Re: Help in creating script to monitor exe memory utilization on server

      Do we have any script readily available for this.. The link which you gave me gave 3 different scripts.. Procees,Stop and start etc..

      Can you plz help me to merge all these scripts..

      Thanks
      Dinesh

      Comment


      • #4
        Re: Help in creating script to monitor exe memory utilization on server

        Euh I hope you can do some scripting, otherwise it would be a good idea to start learning it.
        It will become more and more important though.
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Help in creating script to monitor exe memory utilization on server

          How to find out the memory utilization of one specific Exe file. The Script is only giving the running exe names not utilization.. need your help

          Thanks & Regards
          Dinesh Cholekkavil

          Comment


          • #6
            Re: Help in creating script to monitor exe memory utilization on server

            You didn't read MSDN documentation for the process class, did you?

            -vP

            Comment


            • #7
              Re: Help in creating script to monitor exe memory utilization on server

              Originally posted by dineshtla View Post
              Hi,

              I want to monitor the memory utilization of specific exe "EWBIC.exe" on one of my Windows 2003 server and need to restart the respective service "IC Service" if the specific EWBIC.exe memory utiliztion is 500MB and above

              I want to get any alert / email when any of this happen by running a script after every 10 mints on the server.

              Thanks & Regards
              Dinesh Cholekkavil
              Code:
              option explicit
              
              Const PROCESS      = "EWBIC.exe"
              Const MEM_LIMIT_KB = 511999
              Const SERVICE_NAME = "IC Service" '! make sure to use the service name here not the displayname of the service
              
              Dim objSWbemObject, strComputer
              Dim objSWbemServices, objSWbemEventSource
              Dim objProcess, iPID, iMem
              
              strComputer = "."
              
              Set objSWbemServices = GetObject("winmgmts:" _
                 & "{impersonationLevel=impersonate}!\\" _
                 & strComputer & "\root\cimv2")
              
              ' Enable the SeDebugPrivilege privilege to terminate
              ' processes running under a different security context.
              objSWbemServices.Security_.ImpersonationLevel = 3 
              objSWbemServices.Security_.privileges. _
                 addasstring "SeDebugPrivilege", True 
              
              Set objSWbemEventSource = objSWbemServices.ExecNotificationQuery( _
                 "SELECT * FROM __InstanceModificationEvent WITHIN 60 Where (" & _
                 "TargetInstance ISA 'Win32_Process' AND " & _
                 "TargetInstance.Name='" & PROCESS & "' AND " & _
                 "TargetInstance.WorkingSetSize > " & MEM_LIMIT_KB *1024 & ")")
              
              On Error Resume Next
              Do: Set objSWbemObject = objSWbemEventSource.NextEvent()
              
                 Select Case objSWbemObject.TargetInstance.Path_.Class
              
                   Case "Win32_Process"
                     wscript.sleep 10000 ' wait 10 seconds then re-check mem usage by this process
              
                     For Each objProcess in getobject("winmgmts://").instancesof(_
                       "Win32_Process Where Name = '" & PROCESS & "' AND WorkingSetSize > " & MEM_LIMIT_KB *1024)
                       iPID = objProcess.Processid
                       iMem = objProcess.WorkingSetSize /1024
              
                       objProcess.Terminate()  ' optional
              
                       call notifyMe (iPID, iMem)
              
                       ' stop/start service (do not use its displayname here)
                       With objSWbemServices.Get("Win32_Service.Name='"  & SERVICE_NAME & "'")
                         .StopService()
                         wscript.sleep 10000 ' wait 10 seconds
                         .StartService()
                         wscript.sleep 10000 ' wait 10 seconds
                       End With
                     Next
              
                 End Select
              
              Loop
              
              Sub notifyMe (PID, Mem)
              
                 With CreateObject("WScript.Shell")
                   .popup PROCESS & " [ID " & PID & "] terminated " _
                     & "because its memory usage was: " & Mem & " kb", _
                     5, strComputer & " Event", 0+64
                 End With
                 
              End Sub
              WITHIN 60 is the polling interval in seconds. It should not be set smaller than 1 sec. If you like to check every 5 minutes set the value to 300

              The code in sub "notifyMe" can be replace by e-mailsending code.

              You could enhance the script so it can also monitor the state of the service, to ensure the service will be restarted anytime it stopped for what ever reason.

              additionally... you could schedule a watchdog script waching the monitor script's back. Execute the watchdog script periodically to check if the above monitor script is still running, if it is terminated for some reason it is launched it again by the watchdog.


              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X