Click here to Skip to main content
15,843,962 members
Articles / Programming Languages / C#

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.3K   1.4K   23   10
A COM+ monitoring application.

Image 1


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


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.
public ArrayList GetErrors(uint ResponseTimeLimit, 
                                uint ObjectsLimit)

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

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.

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;
    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 = 
               IntPtr(appDataPtr.ToInt32() + (appIndex * appDataSize)), 
    // Get information about running application
    uint nClsIDCount;
    appDataPtr = new IntPtr();
        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 = 
           IntPtr(clsIDDataPtr.ToInt32() + (clsIDIndex * clsIDDataSize)), 
        // 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 
               appData.m_dwAppProcessId, clsIDData.m_dwRespTime, 
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.

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


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 10:26
Bimal Kothari28-Apr-08 10:26 
Generalservices get HANGS Pin
Bimal Kothari28-Apr-08 10:03
Bimal Kothari28-Apr-08 10:03 

Now using new Comonitor - A COM+ Monitor sample.

I have also converted it to windows services and but here I am facing the problem that after some times services get HANGS.

Please let me know the same code I have converted for the service but don’t’ find the reason why services get HANGS with the same code.

QuestionProject Installment Pin
Phoenix073022-Apr-08 13:22
Phoenix073022-Apr-08 13:22 
GeneralException Occured Pin
msubhash28-Feb-07 4:52
msubhash28-Feb-07 4:52 
GeneralRe: Exception Occured Pin
RStern30-Jul-07 0:01
RStern30-Jul-07 0:01 
GeneralRe: Exception Occured Pin
msubhash31-Jul-07 1:25
msubhash31-Jul-07 1:25 
GeneralException Pin
razishamai2-Jan-06 6:27
razishamai2-Jan-06 6:27 
GeneralRe: Exception Pin
Martin Richards6-Mar-14 3:00
Martin Richards6-Mar-14 3:00 
GeneralThanks Pin
Egil Hogholt12-Dec-05 9:02
Egil Hogholt12-Dec-05 9:02 
GeneralCommonitor Pin
sternr7-Dec-05 22:26
sternr7-Dec-05 22: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.