QuickCounters.net is a shared source library for managing the rapid creation of custom Windows performance counters for use in performance tests and operational monitoring.

The idea is to provide an API that simplifies the process of gathering a large number of statistics for each “request” in your system, whether coarse or fine-grained – and to deal easily with the deployment task.

The process for using QuickCounters.net can be described in three easy steps…

1) Create an XML file that describes the portions of your application you wish to instrument. Define a “Component” for each logically separate area of your application (you may just have one component defined for the typical web service or orchestration.) Components should (ideally) not span across process boundaries. Within each Component, define “RequestTypes” for each area of your Component that you would like to measure. The InstrumentedApplication.xsd schema describes this file, but a simple example is enough to get the idea:
<?xml version="1.0" encoding="utf-8" ?>
<InstrumentedApplication>
   <Name>POApplication</Name>
   <Description>POApplication</Description>
   <Component>
      <Name>SubmitPOWebService</Name>
      <Description>Counters for the SubmitPO web service</Description>
      <RequestTypes>
         <RequestType>
            <Name>SubmitPO</Name>
            <Description>Purchase order request web method as a whole.</Description>
         </RequestType>
         <RequestType>
            <Name>SubmitPO_ERPCall</Name>
            <Description>Call to ERP system made when submitting a PO.</Description>
         </RequestType>
      </RequestTypes>
   </Component>
   <Component>…</Component>
</InstrumentedApplication>

Each RequestType that you define will have a performance object (aka performance category) created that is named “Component:RequestType” (i.e. “SubmitPOWebService:SubmitPO”.) These performance objects will have the following eight performance counters defined for them:
  • Requests Started
  • Requests Executing
  • Requests Completed
  • Requests Failed
  • Request Execution Time
  • Requests/Sec
  • Requests/Min
  • Requests/Hour
Each Component that you define will have a performance object defined for it named after the component, with a single counter called “Process UpTime” that reports how long the hosting process for your component has been running. This provides context for the Requests Started/Completed/Failed counters.

2) Deploy this XML file using QuickCounters.net. The QuickCounters.net.dll assembly contains an “installer” class that can be used with “installutil.exe” (or called via an MSI custom action.) InstallUtil is appropriate while developing, whereas an MSI is appropriate when deploying to a server environment.

A developer would execute:
installutil /quickctrconfig=c:\temp\POApplication.Perf.xml QuickCounters.net.dll

where POApplication.Perf.xml is the name of the XML file described above. The installer within QuickCounters.net.dll will handle all installation (and un-installation) tasks. (As an alternative, a developer can use the “Install” menu item provided within the QuickCounters viewer utility.)

After deploying this XML file using QuickCounters.net, the “report” view within perfmon when viewing these counters would look as follows:

Perfview1.jpg

3) Within your code, use the static “Attach” method on the RequestType class as a factory method to create RequestType instances. (These RequestType instances can be short or long lived – the implementation relies on a caching mechanism for the underlying PerformanceCounter classes. However, instances should not be shared across threads.) The “Attach” method takes the name of the Component and the name of the RequestType as string parameters.

(If you are doing BizTalk work, you can pass the orchestration identifier to “Attach” as well, via YourOrchName(Microsoft.XLANGs.BaseTypes.InstanceId). This causes orchestration dehydration and suspension to be tracked, which is important since you might finish execution on a different server than where you began.)

Once you have a RequestType instance, call the “BeginRequest” method, followed by “SetComplete” or “SetAbort” depending on whether your requests ends successfully or fails. (If you are starting or ending more than one request simultaneously, you can pass an integer.)
RequestType request = RequestType.Attach("SubmitPOWebService","SubmitPO”,true);

Request.BeginRequest();
try
{
   // Real work occurs here
   // …
   //
   request.SetComplete();
}
catch
{
   request.SetAbort();
}


Simplest Sample

Motivation

Home

Last edited Dec 14, 2006 at 1:26 PM by scolestock, version 3

Comments

No comments yet.