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.
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:
<section name="CustomWorkflowRuntimeSettings" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<CustomWorkflowRuntimeSettings Name="workflowRuntime" EnablePerformanceCounters="true" />
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.
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.
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.
- Workflows Aborted
- Workflows Aborted / sec
- Workflows Completed
- Workflows Completed / sec
- Workflows Created
- Workflows Created / sec
- Workflows Executing
- Workflows Idle / sec
- Workflows In Memory
- Workflows Loaded
- Workflows Loaded / sec
- Workflows Pending
- Workflows Persisted
- Workflows Persisted / sec
- Workflows Runnable
- Workflows Suspended
- Workflows Suspended / sec
- Workflows Terminated
- Workflows Terminated / sec
- Workflows Unloaded
- 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:
- Workflow Created
- 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:
- Text file (Comma or Tab delimited)
- Binary file
- Binary Circular file
- 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).
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.