Click here to Skip to main content
15,885,063 members
Articles / Programming Languages / C#
Article

Comonitor - A COM+ Monitor

Rate me:
Please Sign up or sign in to vote.
4.50/5 (7 votes)
7 Dec 20052 min read 53.6K   1.4K   23   10
A COM+ monitoring application.

Image 1

Introduction

This article provides system administrators with a tool to monitor COM+ applications (Remote and Local) the managed way.

Background

As a system administrator, I use the COM+ MMC on a daily basis looking for deadlocked or un-disposed components. After crawling the web for quite some time, I managed to find a small piece of C# code which helped me build this monitoring application. (The code was found in Egil Hogholt's blog, the C# version was added as a comment by Mark.)

Comonitor Architecture

The core of the application is the "COMSVCSLib.TrackerServer" object which returns info only for the local server. To overcome this problem, I decided to wrap the core code (using the TrackerServer object) in a WebService which will be installed on each of my servers. My client application uses SOAP to call the web service on a remote server (the remote server name is given as a parameter at runtime).

Understanding the ComonitorService

The ComonitorService has only one WebMethod ("GetErrors") which gets two uint parameters from the client:

  • "ResponseTimeLimit" - uint representing the response time (m\s) which the client considers as a deadlock.
  • "ObjectsLimit" - uint representing the number of un-disposed components which the client considers as an error.
C#
[WebMethod]
[XmlInclude(typeof(Comonitor.OverLimitObject))]
public ArrayList GetErrors(uint ResponseTimeLimit, 
                                uint ObjectsLimit)

"GetErrors" returns an ArrayList of ComonitorService.OverLimitObjects with all the problematic components.

C#
public class OverLimitObject
{
    public string  PackageName;
    public string  ComponentName;
    public uint    PID;     
    public uint    ResponseTime;
    public uint    Objects;
}

"OverLimitObject" contains all the necessary information received from the "COMSVCSLib.TrackerServer" object.

Using the "COMSVCSLib.TrackerServer"

The following code is the core of the Comonitor application. It uses the "COMSVCSLib.TrackerServer" object to query the COM Catalog for (only) the running components. For each component which corresponds to the given limit parameters, we create a "ComonitorService.OverLimitObject" containing the relevant data from the component's statistics.

C#
ArrayList retVal = new ArrayList();
IntPtr clsIDDataPtr    = IntPtr.Zero;
IntPtr appDataPtr    = IntPtr.Zero;
COMSVCSLib.IGetAppData getAppData = null;

// Get an instance of the internal com+ tracker objet
COMSVCSLib.TrackerServer comPlusTrackerType;
comPlusTrackerType = new COMSVCSLib.TrackerServerClass();
getAppData = (COMSVCSLib.IGetAppData)comPlusTrackerType;

// Get a list of running application
uint appCount;
unsafe 
{ 
    getAppData.GetApps(out appCount, new IntPtr(&appDataPtr)); 
}

// Step through the list of running application
int appDataSize = Marshal.SizeOf(typeof(COMSVCSLib.appData)); 
for(int appIndex=0; appIndex<appCount; appIndex++) 
{
    COMSVCSLib.appData appData = 
               (COMSVCSLib.appData)Marshal.PtrToStructure(new 
               IntPtr(appDataPtr.ToInt32() + (appIndex * appDataSize)), 
               typeof(COMSVCSLib.appData));
    
    // Get information about running application
    uint nClsIDCount;
    appDataPtr = new IntPtr();
    unsafe
    {
        getAppData.GetAppData(appData.m_idApp, out nClsIDCount, 
                                    new IntPtr(&clsIDDataPtr)); 
    }
    
    // Step through the information
    int clsIDDataSize = Marshal.SizeOf(typeof(COMSVCSLib.CLSIDDATA));
    for(int clsIDIndex=0; clsIDIndex<nClsIDCount; clsIDIndex++) 
    {
        COMSVCSLib.CLSIDDATA clsIDData = 
           (COMSVCSLib.CLSIDDATA)Marshal.PtrToStructure(new 
           IntPtr(clsIDDataPtr.ToInt32() + (clsIDIndex * clsIDDataSize)), 
           typeof(COMSVCSLib.CLSIDDATA));
        
        // Checks if any parameter is over the limit
        // (which was provided by the user)
        if ((clsIDData.m_cBound >= ObjectsLimit) || 
            (clsIDData.m_dwRespTime >= ResponseTimeLimit))
        {
            //Creates Over Limit Objects and adds it to retVal
            OverLimitObject objOL = new 
               OverLimitObject(GetPackageNameByPID(appData.m_dwAppProcessId), 
               GetComponentNameByCLSID(clsIDData.m_clsid.ToString()), 
               appData.m_dwAppProcessId, clsIDData.m_dwRespTime, 
               clsIDData.m_cBound);
            retVal.Add(objOL);
        }
    }
}
return retVal;

The Client

In this article, I also included a Windows client application which uses the "ComonitorService". The example client application calls the WebService on a specified computer every given time period (optional) and provides the sys admin with the capability to shut down a problematic package on the specified server. If there are COM+ packages which you don't want to be checked, such as: system application, IIS utilities etc., you can add the package names into the client's App.config inside the "NonErrorPackages" key.

XML
<add key="NonErrorPackages" value="System Application,IIS Utilities" />

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRequired Solution Pin
Bimal Kothari28-Apr-08 9:26
Bimal Kothari28-Apr-08 9:26 
Generalservices get HANGS Pin
Bimal Kothari28-Apr-08 9:03
Bimal Kothari28-Apr-08 9:03 
QuestionProject Installment Pin
Phoenix073022-Apr-08 12:22
Phoenix073022-Apr-08 12:22 
GeneralException Occured Pin
msubhash28-Feb-07 3:52
msubhash28-Feb-07 3:52 
GeneralRe: Exception Occured Pin
RStern29-Jul-07 23:01
RStern29-Jul-07 23:01 
GeneralRe: Exception Occured Pin
msubhash31-Jul-07 0:25
msubhash31-Jul-07 0:25 
GeneralException Pin
razishamai2-Jan-06 5:27
razishamai2-Jan-06 5:27 
GeneralRe: Exception Pin
Martin Richards6-Mar-14 2:00
Martin Richards6-Mar-14 2:00 
GeneralThanks Pin
Egil Hogholt12-Dec-05 8:02
Egil Hogholt12-Dec-05 8:02 
GeneralCommonitor Pin
sternr7-Dec-05 21:26
sternr7-Dec-05 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.