Monitoring Processes for Reliability

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Reliability measures the mean time between failures for an application; that is, how long an application runs before it fails. For many applications, attempting to measure this type of reliability is irrelevant. For example, Microsoft Word typically runs only as long as a user needs it. When finished, the user closes Word. The fact that Word might be running only for a few minutes does not necessarily tell you anything about the reliability of the application. Instead, it typically indicates only that the user simply did something such as open a document and print it and then closed Word.

Other applications, such as many database applications, are designed to run continuously. For these applications, reliability measurements are much more meaningful. You can use WMI event subscriptions to help monitor the reliability of those processes.

Event subscriptions can notify you any time a process is created or deleted on a computer. This allows you to carry out reliability monitoring: you can record the time each process is created and the time each process is deleted, and then calculate the reliability of the application (the amount of time that elapsed between process creation and deletion).

Monitoring process creation and deletion also provides a rudimentary but useful way to monitor software use in your organization. You can use this approach to keep track of the number of times software applications are started and to determine the length of a typical application session. This provides you with a rough estimate of which programs are used most often, and for how long.

You can also use process creation monitoring to help control the services and applications that run on a computer. For example, in an enterprise setting, servers are typically dedicated to single tasks, such as allocating IP addresses or managing print queues. By monitoring process creation, you can be notified immediately any time a different service or application starts on one of these servers.

In addition to keeping track of each time a process is created, you can use WMI to keep track of each time a process is deleted. Monitoring process deletion helps you ensure that critical applications remain running at all times. For example, you might write a script that monitors a database application on a computer. If the application fails, the process is deleted. The script can identify the fact that the database process no longer exists and automatically restart the application.

Note

  • By monitoring process deletion, you can determine that an application has finished running. However, you cannot determine whether the application finished running because a user closed it or because it failed.

Scripting Steps

The scripts for monitoring process creation and process deletion are similar.

Monitoring process creation

Listing 14.2 contains a script that monitors process creation using a temporary event consumer. To carry out this task, the script must perform the following steps:

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

    To restrict data retrieval to processes, a WHERE clause is included to limit data retrieval to instance creations involving the Win32_Process class (WHERE TargetInstance ISA Win32_Process ).

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

    To stop monitoring, you need to either log off the computer or terminate the process the script is running in.

  5. Use the NextEvent method to retrieve the properties of each event when it occurs.
  6. Each time a process is created, echo the name of that process and the current time (Now). The current time indicates the time the process was created.

Listing 14.2   Monitoring Process Creation

1 2 3 4 5 6 7 8 9 10 11 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _           ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent " _         & "WITHIN 10 WHERE TargetInstance ISA 'Win32_Process'") i = 0 Do While i = 0     Set objLatestProcess = colMonitoredProcesses.NextEvent     Wscript.Echo objLatestProcess.TargetInstance.Name, Now Loop

Monitoring process deletion

To monitor process deletion, use a script similar to Listing 14.2 but substitute __InstanceDeletionEvent for __InstanceCreationEvent in the ExecNotificationQuery, as shown in Listing 14.3.

Listing 14.3   Monitoring Process Deletion

1 2 3 4 5 6 7 8 9 10 11 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _     ExecNotificationQuery("SELECT * FROM __InstanceDeletionEvent " _         & "WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'") i = 0 Do While i = 0     Set objLatestProcess = colMonitoredProcesses.NextEvent     Wscript.Echo objLatestProcess.TargetInstance.Name, Now 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