Last updated: 02/23/99, Initial Release
Do you currently monitor the activity of IIS with Performance Monitor? No? You should start to as you can gather really interesting information about IIS and ASP (see article at 15 Seconds)! Though Performance Monitor is really cool, it has one disadvantage - it is quite hard to get readings of the performance counters across the Net.
This is where the AspQPerfCounters component is stepping in by providing an easy interface for retrieving performance counters. It is implemented as Automation component, not using ASP intrinsic objects, therefore allowing you to use it in any application (Excel sample is included). Note that it works only on Windows NT, however, one nice feature is that if you have a standard setup, it also works under the IUSR account - no special security permissions are needed.
Related Articles 15 Seconds: Debugging Production Active Server Pages in IIS 4.0
Below you can find an example how you usually call into the component:
Set objQPerfCnt = CreateObject("Softwing.AspQPerfCounters") bResult = objQPerfCnt.OpenQuery() bResult = objQPerfCnt.AddCounter("\\.\Active Server Pages\Errors During Script Runtime") bResult = objQPerfCnt.CollectQueryData() varResult = objQPerfCnt.GetFormattedCounterVal(_ "\\.\Active Server Pages\Errors During Script Runtime", 0) bResult = objQPerfCnt.CloseQuery()
After creating the object, you have to open a performance query. After this has been done, you can go about adding as many counters to the query as you like. The syntax is \\computername\object\counter - with the local computer being represented by a simple dot (\\.\). The \object component is required; it specifies the object that contains the counter. If the object supports variable instances, then you must also specify an instance string. The format of the (ParentInstance/ObjectInstance#InstanceIndex) portion depends on the type of object specified. If the object has simple instances, then the format is just the instance name in parentheses. For example, an instance for the Process object would be the process name such as (Explorer) or (MyApp). If you want to find out about the objects and counters, simply open Windows NT Performance Monitor from the Administrative Tools menu and open the Add To Chart dialog - there you can find all necessary information (see Figure).
After having added all counters, you call CollectQueryData to get the data for the performance counters. Next, use GetFormattedCounterVal to retrieve the value formatted as long (this is the only numerical format currently supported - the second parameter is reserved for this purpose). When you are done, call CloseQuery.
Note that you can call CollectQueryData multiple times to get snapshots of performance counters.
This example monitors the performance counters that are proposed in the 15 Seconds article:
<% @LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<%
' counters to watch
Dim arrFriendlyName, arrCounterPath
arrFriendlyName = Array("Total failed requests","Errors per second (current)",_
"Runtime errors (total)", "Script compiler errors (total)",_
"ASP preprocessor errors (total)")
arrCounterPath = Array("\\.\Active Server Pages\Requests Failed Total", _
"\\.\Active Server Pages\Errors/Sec", _
"\\.\Active Server Pages\Errors During Script Runtime",_
"\\.\Active Server Pages\Errors From Script Compilers", _
"\\.\Active Server Pages\Errors From ASP Preprocessor")
%>
<html>
<head>
<title>Testing AspQPerfCounters</title>
</head>
<h1>ASP Performance Counters for Debugging</h1>
<body bgcolor="#ffffff">
<%
Dim objQPerfCnt, bResult, varResult, i
Set objQPerfCnt = CreateObject("Softwing.AspQPerfCounters")
bResult = objQPerfCnt.OpenQuery()
for i = 0 to UBound(arrCounterPath)
bResult = objQPerfCnt.AddCounter(arrCounterPath(i))
next
bResult = objQPerfCnt.CollectQueryData()
for i=0 to UBound(arrCounterPath)
varResult = objQPerfCnt.GetFormattedCounterVal(arrCounterPath(i), 0)
Response.Write "<b>" & arrFriendlyName(i) & "</b>: "
Response.Write varResult & "<br>" & vbCrLf
next
%>
</body>
</html>
Before using the component you have to register it using the regsvr32 utility: regsvr32 aspperfc.dll.
There are two possible errors you might receive when registering the component: 0x0000007e and 0x0000007f. These are related to the fact that the component relies on a helper dll (pdh.dll), that is part of the Platform SDK but not installed by default with Windows NT. The first error occurs if pdh.dll is not installed on your system at all, and the 7f error occurs if you have a version that is too old.
If you encounter this problem, then download pdh.dll (45KB) and copy it to the winnt\system32 directory and then re-register the component.
Download
(size is approx. 71KB)
The most current version number of the component is 1.0. It is compiled
with Visual C++ 6.0 SP1 using MFC statically linked. It does not work on
platforms other than NT.
If you do have any questions, please feel free to send mail to Christoph Wille.