Announcement

Collapse
No announcement yet.

Script to monitor CPU usage

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

  • Script to monitor CPU usage

    Hi All,

    Guys do you have a script to monitor cpu usage of server (2003 or 2008 ) including disk usage and if the lan connection trips or server goes down?

    Seeking on ideas..


    Thanks in advance.

  • #2
    Re: Script to monitor CPU usage

    first google response

    http://forums.cacti.net/post-9117.html
    Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

    Comment


    • #3
      Re: Script to monitor CPU usage

      Hmmmm I would think that something as MRTG would be suitable for you...
      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


      • #4
        Re: Script to monitor CPU usage

        yah MRTG(open source), but any other than that?

        I need scripts only... thanks


        @camel link, the script is intended for cpu, i need also scripts to monitor disk space usage of the server... do you have one for this?? TIA.
        Last edited by rexsniper; 16th July 2010, 20:55.

        Comment


        • #5
          Re: Script to monitor CPU usage

          Scripts don't "monitor" things. Scripts are executed by something in response to an event; they don't run constantly in the background.

          Why do you only require scripts, rather than MRTG being an option?
          Gareth Howells

          BSc (Hons), MBCS, MCP, MCDST, ICCE

          Any advice is given in good faith and without warranty.

          Please give reputation points if somebody has helped you.

          "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

          "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

          Comment


          • #6
            Re: Script to monitor CPU usage

            Originally posted by rexsniper View Post
            yah MRTG(open source), but any other than that?

            I need scripts only... thanks


            @camel link, the script is intended for cpu, i need also scripts to monitor disk space usage of the server... do you have one for this?? TIA.
            I did have in my last job. I could have again, or you could find it the same way i found that one for you.

            also look into scriptomatic
            Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

            Comment


            • #7
              Re: Script to monitor CPU usage

              Actually I meant nagios...
              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


              • #8
                Re: Script to monitor CPU usage

                Originally posted by gforceindustries View Post
                Scripts don't "monitor" things. Scripts are executed by something in response to an event; they don't run constantly in the background.
                That is not entirely true.
                WMI returns not only information but can also wait for certain events. If the events occur, an action will be started.
                Originally posted by [url=http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-18-wmi-windows-management-instrumentation.aspx#wmi-events]"Master-PowerShell" | With Dr. Tobias Weltner[/url]

                In the process, WMI can alert you when one of the following things involving a WMI instance happens:

                __InstanceCreationEvent: A new instance was added such as a new process was started or a new file created.
                __InstanceModificationEvent: The properties of an instance changed. For example, the FreeSpace property of a drive was modified.
                __InstanceDeletionEvent: An instance was deleted, such as a program was shut down or a file deleted.
                __InstanceOperationEvent: This is triggered in all three cases.

                You can use these to set up an alarm signal. For example, if you want to be informed as soon as freespace on c: is less than 1288078796 byte, type:
                SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DeviceID = 'C:' AND TargetInstance.freespace < 1288078796
                "WITHIN" specifies the time interval of the inspection and "WITHIN 10" means that you want to be informed no later than 10 seconds after the event occurs. The shorter you set the interval, the more effort involved, which means that WMI will require commensurately more computing power to perform your task. As long as the interval is kept at not less than one second, the computation effort will be scarcely perceptible.

                (see also, technet: 'Enhanced WMI Monitoring Scripts' (VBScript) )
                Here is an VBScript example,
                "Continually monitoring a CPU and freespace of a local drive of a Windows Host"
                Code:
                Const CPU_0_LoadPercent  = 90  '%
                Const FreeSpacePercent_C = 30  '%
                
                ' CPU_0_LoadPercent = Load capacity of the first processor, averaged to
                ' the last second. Processor loading refers to the total computing 
                ' burden for each processor at one time.
                
                strComputer = "."   ' name of remote computer  OR, 'dot' is local
                
                DIM objSWbemObject
                Set objSWbemServices = _
                   GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                
                For Each objDisk in objSWbemServices.ExecQuery _ 
                   ("Select Size, DeviceID " & _ 
                   "from Win32_logicalDisk where DeviceID='c:' ",,48) 
                   FreeSpace_C = int(objDisk.size * (FreeSpacePercent_C * 0.01)) 'bytes
                Next
                
                Set objSWbemEventSource = objSWbemServices.ExecNotificationQuery( _
                   "SELECT * FROM __InstanceModificationEvent WITHIN 5 " & _
                   "WHERE (" & _
                   "TargetInstance ISA 'Win32_Processor' AND " & _
                   "TargetInstance.DeviceID='CPU0' AND " & _
                   "TargetInstance.LoadPercentage > " & CPU_0_LoadPercent & ") " & _
                   "OR (" & _
                   "TargetInstance ISA 'Win32_LogicalDisk' AND " & _
                   "TargetInstance.DeviceID = 'C:' AND " & _
                   "TargetInstance.freespace < " & Freespace_C & ")")
                
                Do
                   Set objSWbemObject = objSWbemEventSource.NextEvent()
                
                   With CreateObject("WScript.Shell")
                
                   Select Case objSWbemObject.TargetInstance.Path_.Class
                     Case "Win32_Processor"
                       .popup "Load Percentage on CPU0 exceeded " & CPU_0_LoadPercent _
                         & "%.", 5, strComputer & " Event", 0+64
                     Case "Win32_LogicalDisk"
                       .popup "Free space on C: is below " & FreeSpacePercent_C _
                         & "%.", 5, strComputer & " Event", 0+64
                   End Select
                
                   End With
                
                Loop
                \Rems
                Last edited by Rems; 20th July 2010, 11:59.

                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


                • #9
                  Re: Script to monitor CPU usage

                  wow.. this is great... I try to test the scripts tom., thank you sir!

                  (Thanks for enlighting them)

                  Comment

                  Working...
                  X