Monitoring Service Reliability

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Reliability monitoring enables you to track the mean time between service failures. The mean time between failures tells you the amount of time you can expect a service to run before it fails. A service with a mean time between failures of 1000 hours is expected to run approximately 1000 hours before encountering problems.

Knowing the mean time between failure can help you prevent problems before they occur. For example, you might have a service that fails every 10 days because of a memory leak. Rather than wait for the service to fail (perhaps at a highly inconvenient time for your users), you might periodically schedule the service to stop and restart at a time that minimizes the impact on users, on other services, and on other parts of the computing environment.

Reliability monitoring can also tell you how long it takes for a service to be restored in the event that it does fail. For example, your reliability statistics might show that it takes 6 hours to fully restore a particular service. This information can help you plan routine service maintenance: If you need to upgrade or reconfigure the service, schedule this maintenance during a 6-hour block that minimally disrupts users.

You can create an event subscription that notifies you each time a service changes state (for example, goes from running to stopped). By saving these state changes to a database, you can calculate the mean time between failures and the time required to restore full functionality.

Scripting Steps

Listing 15.3 contains a script that uses a temporary event subscription to monitor changes in service state. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the target computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2 on the target computer, and set the impersonation level to "impersonate."
  3. Use the ExecNotificationQuery method to register for notification each time there is an instance modification (each time an instance within the namespace changes in some way).

    Because the script monitors only changes to services, a Where clause is included to limit monitoring and data retrieval to instance modifications that involve the Win32_Service class.

  4. Create a loop that allows the script to run indefinitely.

    To stop monitoring, you need to terminate the script.

  5. Use the NextEvent method to retrieve each event when it occurs.
  6. Each time a service is modified in some way, the script checks to see whether the current state of the service differs from the previous state of the service. If it does not, the script resumes by waiting for the next event.

    Comparing the previous state with the current state enables you to identify whether the modification involved a change in service state. For example, a change in service state would be indicated by a service that was started when last monitored but is now stopped. If the previous and current states are the same, the modification did not involve service state but instead reflects a change to some other property of the service (such as changing the start mode from manual to autostart).

  7. If the service states differ, echo the display name of the service, its current state, and its previous state.

Listing 15.3   Monitoring Changes in Service Status by Using a Temporary Event Subscriber

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
strComputer = "." Set objWmiService = GetObject("winmgmts:" & _     "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objWmiEventSource = objWMIService.ExecNotificationQuery _     ("SELECT * FROM __InstanceModificationEvent " & _         "WITHIN 30 WHERE TargetInstance ISA 'Win32_Service'") Do     Set objService = objWmiEventSource.NextEvent     If objService.TargetInstance.State <> _        objService.PreviousInstance.State Then            Wscript.Echo objService.TargetInstance.DisplayName & _                " is " & objService.TargetInstance.State & _                    ". The service previously was " & _                        objService.PreviousInstance.State & "."     End If Loop

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net