Tuesday, November 10, 2009

Monitoring WF based workflows using Performance Monitoring Tool (Perfmon.exe)

Administrators need some way to monitor applications running in production. One way to provide such monitoring facility is to provide performance counters for the application. These counters can be viewed and logged using Performance Monitoring utility (Perfmon.exe) available with Windows.


Among the list of features provided with Windows WF, the easiest is using the Performance Counters. This is a limited option for viewing workflow runtime information. You can get details like the number of workflows being created and completed. This very limited option but can be of much use sometimes.


We divide this discussion in two parts. In first part we will be discussing about creating WF application which emits this information to be collected by a Performance monitoring application. Next we would be discussing how we can monitor these counters using available Windows tool (Perfmon.exe).


Creating WF workflow based application:


Create Sequential WF Console application Project:

Start Visual Studio and create a Sequential WF Console application. Name this project as WFPerformanceCounter.


Designing Workflow:

Open workflow1.cs in the WF designer. Drag and drop a Delay activity respectively. Take properties and specify a delay of 10 seconds (00:00:10) for delay activity.


Creating App.config file:

Add application configuration file to the project and name it as app.config. Delete all the xml data from this file and paste the following:


<?xml version="1.0"?>

<configuration>

<configSections>

<section name="CustomWorkflowRuntimeSettings" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

</configSections>

<CustomWorkflowRuntimeSettings Name="workflowRuntime" EnablePerformanceCounters="true" />

</configuration>


This enables the runtime from emitting performance counter information for any monitoring application. If you don’t want this information to be made available to the monitoring application, just set EnablePerformanceCounter attribute of CustomWorkflowRuntime element as “false”.


Updating Hosting Class:

By default, Visual studio creates Program.cs as the hosting class. This creates runtime object and initializes the workflow.


Add reference of System.Configuration assembly to the project. Specify System.Configuration namespace in Program.cs. This would provide System.Workflow.Runtime.Configuration.WorkflowRuntimeSection class to the application.


Specify the System.Configuration namespace in Program.cs.


using System.Configuration;


Update the initialization code of runtime object (Main method) as follows:


using (WorkflowRuntime workflowRuntime2 = new WorkflowRuntime( "CustomWorkflowRuntimeSettings"))

{…}


The above code specifies which configuration settings should be used for creating the runtime object.


Our application is now all set for providing performance counter information for the monitoring tool.


Note:

Remember that the default behavior of runtime is to emit counter information for collection. We can suppress this behavior by specifying this in the configuration file as discussed already.


Monitoring WF Performance Counters:

You can view the list of the available performance counters in Performance Monitor tool (Perfmon.exe). For all of those who are not available about this tool, this is a performance monitor tool available with windows. It lets you view the various system and application level performance counters. You can start it by typing “Perfmon.exe” on the Run command in Start menu.


There are following counters available for Windows WF.


  1. Workflows Aborted
  2. Workflows Aborted / sec
  3. Workflows Completed
  4. Workflows Completed / sec
  5. Workflows Created
  6. Workflows Created / sec
  7. Workflows Executing
  8. Workflows Idle / sec
  9. Workflows In Memory
  10. Workflows Loaded
  11. Workflows Loaded / sec
  12. Workflows Pending
  13. Workflows Persisted
  14. Workflows Persisted / sec
  15. Workflows Runnable
  16. Workflows Suspended
  17. Workflows Suspended / sec
  18. Workflows Terminated
  19. Workflows Terminated / sec
  20. Workflows Unloaded
  21. Workflows Unloaded / sec


Performance counters may be monitored for either any individual or all instances of WF runtime engines.

Select all the required counters and select “Add”. This would show the counters data on the System Monitor. For our purpose we add two counters:

  1. Workflow Created
  2. Workflow Completed

With all the above configurations, when we run our WFPerformanceCounter application the monitor should have following view:



Note that for this view you should have “View Current Activity” option selected with selecting Graph view.


Persisting Performance Counter Logs:

In addition to view online providence of counter information, we can also log them selectively using the same Performance monitor tool. The available destination of this information may be following:


  1. Text file (Comma or Tab delimited)
  2. Binary file
  3. Binary Circular file
  4. SQL Database


Binary Circular file starts overwriting old data from the beginning with the new data once the file reaches its maximum limit. This is useful when we are certain that we already have reviewed and audited old log information.

Persisting information using SQL Database could give us flexibility for developing tools for users so that they can view the information anytime. The better option is to create SQL Server Reporting Services based reports and reviewing these logs should be part of the overall audit review process.


No matter where you log this information i.e. file or database, you can always view it later on using the same tool (Performance Monitor Tool).



Monitoring Remotely:

As you all know, for using this Performance monitoring tool, you don’t have to be physically logged in to the machine. You can always view these counters manually from any machine on the network. The other option is that you can create logs in files or database and you can create reports based on these logs.


No comments: