NT Performance Monitor Customizable COM Alerter



Home Page: http://www.OrbitDevelopment.com

Environment: Windows NT Server and Workstation 4.0

Problem

Companies do not have NT Monitorig systems to be able to determine, and notify engineering, when an NT Server resource gradually degrades, or become non-existing. There are tools available to do so, but they can become quite expensive.

If you are tired of your current monitoring system, like a phone call at 3:00am from your boss saying, “The server is down!”, this tool is for you.

Goal

Find an easy low cost solution to resolve the problem. The solution must be cheap and effective, at the same time very customizable.

Solution

NT currently includes “NT Performance Monitor” (PerfMon). PerfMon allows users to see performance graphs on certain NT resources. It also allows users to set “Alerts” for the same NT resources that you can graphically monitor.

Adding an “Alert” allows you to “Run a Program on Alert”. This is the basis for our solution. I have created a program called “PerfMonitorAlerter.exe”. When setting an alert, you would use PerfMonitorAlerter as the program to run on any alert you set, for example:

PerfMonitorAlerter “Memory is running over 90 megabytes”

PerfMonitorAlerter process uses COM objects to process the alert message specified in its parameter text: “Memory is running over 90 megabytes”.

Technology

When PerfMon triggers the alert, it will start PerfMonitorAlerter.exe program with the message (“Memory is running over 90 megabytes”) as it fisrt parameter.

PerfMonitorAlerter.exe will check registry path store at

       HKEY_LOCAL_MACHINE\\SOFTWARE\\www.OrbitDevelopment.com\\PerfMonitorAlerter






for any COM CLSIDs that implement a common interface, IAlertInterface:



    import "oaidl.idl";
    import "ocidl.idl";
	[
		object,
		uuid(B6C11879-3003-11D3-9257-00104BF7F161),

		helpstring("IAlertInterface Interface"),
		pointer_default(unique)
	]
	interface IAlertInterface : IUnknown
	{
		[helpstring("method EmergencyAlert")] HRESULT EmergencyAlert([in] BSTR bAlertName);
	};

In this code example case, PerfMonitorAlerter.exe will:

  • Create an instance of object “{B6C1187A-3003-11D3-9257-00104BF7F161}”.
  • Query Interface IAlertInterface
  • Call method pIAlertInterface ->EmergencyAlert(“Memory is running over 90 megabytes” )
  • Release the object

        : : : : : : : : : : : :
        : : : : : : : : : : : :

        // Registry COM Iterator

        while ( TRUE )
        {
            char  szSubkey[ 64 ];
            DWORD cbSubkeySize = 64;
            CLSID clsidAlerter;
            BSTR  bstrCLSIDFromReg = NULL;

            if ( ERROR_NO_MORE_ITEMS == ::RegEnumKeyEx( regKey, regEnumIndex++, szSubkey, &cbSubkeySize, 0, 0, 0, 0 ) )
                break;

            // Convert to BSTR, the convert it CLSID
            bstrCLSIDFromReg = charToBstr(szSubkey);
            ::CLSIDFromString(bstrCLSIDFromReg, &clsidAlerter);
            if (bstrCLSIDFromReg) ::SysFreeString(bstrCLSIDFromReg);

            // Create object to notify
            if ( (bstrServiceName != NULL) && S_OK == ::CoCreateInstance( clsidAlerter, NULL, CLSCTX_INPROC_SERVER, IID_IAlertInterface, (void**) &pIAlertInterface ))
            {
                // Send Alert
                pIAlertInterface->EmergencyAlert(bstrServiceName);
            }

            // Cleanup/Release the object
            if (pIAlertInterface) pIAlertInterface->Release();
        }

        : : : : : : : : : : : :

This architecture will allow create one, or many, COM object to be notified, without concern for implementation details. The COM objects implementing IAlertInterface may send emails, log entries, call a pager, etc..

Although this is not the answer to all NT monitoring problems, it is an easy, customizable and powerful approach using COM communication technology.

Documentation Note

For detailed documentation (Word document), please feel free to contact
me

Downloads

Download PerfMonitorAlerter application – 14 kb
Download source – 8 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read