By This email address is being protected from spambots. You need JavaScript enabled to view it.

This tip demonstrates a Universal Agent solution to monitor the availability of a selection of Windows processes over time. This solution is necessary when using ITM 6.1 to monitor the lifetime of critical processes: how long have they been up, when they went down, have the restarted etc.

Design

The Universal Agent solution consists of three files:

process_list.txt
A user-customisable list of which processes to monitor. The format is simply the Image Name of the process as it appears in Task Manager, e.g. "notepad.exe", "DataServer.exe" etc. Each process must appear on a separate line, e.g.

notepad.exe
perl.exe

This file is read on each cycle of the Universal Agent, and therefore can be edited by the user to add or remove processes as required.

process_find.mdl
A standard Universal Agent metafile, defining the data to return to the Tivoli Enterprise Portal (TEP). In this case it is simply the name of each process monitored and a status code of 1 if it is running and 0 if it is not. Using a number for status will make it easy to process the data in TEP graphs, tables and situations.

//APPL PROCESS_ONLINE
//NAME PROCESS_ONLINE K 60
//SOURCE SCRIPT cscript "e:IBMITMTMAITM6scriptsprocess_find.vbs //nologo"
//ATTRIBUTES DLMSTR=';'
PROCESS_NAME D 12 KEY
STATUS C 9
?>

process_find.vbs

A VBScript that uses WMI to determine if a process if running and compares the results against the contents of the processList.txt file. VBScript was used as it can be deployed and executed natively on Windows machines:

'Force variables to be declared c.f. Perl's use strict
Option Explicit

'location of process list file, change as required to match your environment
Const PROCESS_LIST = "E:IBMITMTMAITM6scriptsprocess_list.txt"

Const FOR_READING = 1
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

'read process list file into array and build WHERE clause for WMI call
Dim processList()
Dim whereClause
whereClause = ReadFile(PROCESS_LIST, processList)

If whereClause <> "" Then
'feed WHERE clause from process list into WMI to see if these processes are running
Dim wmiList
wmiList = WMIProcessLookup(whereClause)

Dim Found
Found = False
'Compare results from WMI with list in file
Dim i, j
For i = 0 to Ubound(processList)
For j = 0 to Ubound(wmiList)
If processList(i) = wmiList(j) Then
'WMI returned process with same name running
Found = True
Exit For
End If
Next

'write result to STDOUT stream to be picked up by UA as PROCESS_NAME;X
'where X is 1 if running and 0 if not, note use of ; as delimiter between the two fields
If Found = True Then
Wscript.Echo processList(i) & ";1"
Else
Wscript.Echo processList(i) & ";0"
End If

Found = False
Next
End If

Function WMIProcessLookup(whereClause)
'connect to WMI
Dim objWMIService
Set objWMIService = GetObject("winmgmts:" & "."& "
ootCIMV2")

'request list of running processes that match our WHERE clause derived from process list file
Dim colItems
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process " & whereClause, "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

'build array with results
Dim resultArray()

Dim o
Dim i
i = 0
For Each o In colItems
Redim Preserve resultArray(i)
resultArray(i) = o.Name
i = i + 1
Next

'if no results return empty array
If i = 0 Then
Redim resultArray(0)
End If

'in VBScript, to return a value, we assign the Function to it
WMIProcessLookup = resultArray
End Function

Function ReadFile(file, processArray)
Dim objFSO
Dim objTextFile

'open process list file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (PROCESS_LIST, FOR_READING)

Dim line
Dim whereClause
Dim i
i = 0

'read file and build WMI WHERE clause from list of process names, e.g. WHERE Description ='notepad.exe' OR Description = 'someImportantProcess.exe'
Do Until objTextFile.AtEndOfStream
line = objTextFile.Readline

'skip blank lines
If line <> "" Then
Redim Preserve processArray(i)
processArray(i) = line

If (0 = i) Then 'First line
whereClause = "WHERE Description = '" & processArray(i) & "'"
Else
whereClause = whereClause & " OR Description = '" & processArray(i) & "'"
End If

i = i + 1
End If
Loop

objTextFile.Close

'return the where clause
ReadFile = whereClause
End Function

?>

Installation

Copy the files to the following locations on each system where the solution is required and you have pre-installed a Universal Agent. Note that the process_list.txt file need to be created.

<INSTALL_ROOT>IBMITMTMAITM6metafilesprocess_find.mdl

<INSTALL_ROOT>IBMITMTMAITM6scriptsprocess_find.vbs

<INSTALL_ROOT>IBMITMTMAITM6scriptsprocess_list.txt

Edit the following line in process_find.mdl to point to the location of process_find.mdl on your system:

//SOURCE SCRIPT cscript "E:IBMITMTMAITM6scriptsprocess_find.vbs //nologo"

Edit the following line in process_find.vbs to point to the location of process_list.txt on your system:

Const PROCESS_LIST = "E:IBMITMTMAITM6scriptsprocess_list.txt"

Open a command window, and change to your <INSTALL_ROOT>IBMITMTMAITM6 directory, and type:

kumpcon validate process_list.mdl

Enter Import when prompted with:
KUMPS065I Do you wish to Import or Refresh this metafile?

Finally recycle your Universal Agent and log into the TEP, you should see a node called ONLINE_PROCESS underneath the Universal Agent for the modified system.

Usage

In order to track process status over time, we need to set our agent solution to record its data historically using the following process:

  1. In the TEP, select Edit -> History Configuration
  2. Choose ONLINE_PROCESS in the 'Select a product' combo-box
  3. Select ONLINE_PROCESS in the 'Select Attribute Groups' table and configure accordingly; ensuring that you press 'Start Collection' when finished and verify that the 'Collection' row value is set to 'Started'.

If you wish to change the processes being monitored, simply update the process_list.txt file on the agent - ensuring one entry per line and the entry is as appears in the 'Image Name' field of task manager. On the next agent cycle, the changes will be displayed in the TEP.

Errors from the VBScript are written to the universal agent error logs automatically by the agent.

Caveats

This solution monitors processes by Image Name, if a process is running via a generic host, such as Java, Perl or the command line; it cannot distinguish between these instances. For example, two Java programs would run under 'java.exe'; this solution as it stands would not be able to tell which one of the two is running at any given time.

Improvements

This solution is Windows only; however, it is possible to develop a similar solution for a Linux/Unix environment using Perl or Shell Script instead on VBScript and parsing the output of process listing commands such as 'ps' instead of using WMI. Moreover, if we mandated that the Windows boxes were to use Perl, we could develop a script to handle the different platforms process listing, and parse the results generically; thus providing an all in one solution.

The WMI process object has a property called CommandLine, which can be used to obtain the command line of each running process. This information can be used to distinguish between processes running with the same name, e.g. java.exe. However, it is only supported on Windows XP, 2003 and upwards. We could modify our script to take this into account, and therefore handle generic hosting processes correctly.

Example

Here is an example workspace that can be created from our Universal Agent's historical data, and hence track the availablity of our chosen processes:

processWorkspace

Twitter Feed

OrbData RT @OrbData: If you missed our #IBMInterConnnect session "NOI: Achieving IT Operations Efficiency" please come to stand 167 & we'll send y…
OrbData If you missed our #IBMInterConnnect session "NOI: Achieving IT Operations Efficiency" please come to stand 167 & we'll send you the slides

Address

Address:
100 Longwater Avenue, Green Park, Reading, RG2 6GP, U.K.
Tel:
+44 (0) 118 945 0130
E-Mail:
This email address is being protected from spambots. You need JavaScript enabled to view it.

markerFind on Google Maps

About Us

Orb Data brings together People, Process and Technology to deliver the cornerstone of business success: the management of IT infrastructure. At our heart are our people. We have unrivalled experience, helping us to achieve an enviable reputation for excellence in project delivery. Because we’re independent, we identify actual issues and help organisations resolve them –from spec to deployment, and beyond –providing the right solution in terms of best of breed technology and support. We offer a refreshingly simple approach to the way we conduct business. We take pride in our abilities to provide first class solutions to business problems, and to conduct working relationships with honesty and integrity.

Follow Us On:

JoomShaper