AVIcode 5.7: Custom Actions and Statistic Counters, Part 2

We have created a very simple custom action in Part 1. Apparently, there is not so much use for a custom action that writes something to a log file every time your application hits some other function.

However, you might utilize the same approach if you wanted to count the number of calls to a particular function. You might use it to calculate average duration of the function calls. And, since AVIcode gives you access to the exception raised inside that function, you might count the number of exceptions raised inside that function. In other words, you might utilize custom actions to get some statistical data about your application.

In general, that would require decent amount of coding. You might have to decide where to store that data, how to share it, etc. Eventually, that might become a separate development project for you.

The good news is that AVIcode provides the ability to collect statistical data right out of the box, and it is done in the form of so-called “Statistic Counters”. In a nutshell, statistic counters are performance counters that get updated by AVIcode through the use of custom actions. Those counters get installed on the agent servers as part of Intercept Agent installation, though you still have to enable them in the configuration file.

Here is the list of available statistic counters (you will see them in the .NET Statistic counters group on the Intercept Agent servers):

– # of Exceptions/sec
– # of Performance violations/sec
– % of Exceptions/sec
– % of Performance violations/sec
– Avg. execution time
– Calls /sec

These counters can provide lots of useful statistic about the application, yet it is really easy to implement alerting in the Operations Manager based on such counters.

So, how do you enable statistic counters?

First of all, you don’t need to write any code. It’s all done by AVIcode already. You just need to configure the counters properly. In order to do that, you will need two files:

– <NAME>.StatisticCounters.Instrument.config
– <NAME>.StatisticCounters.Action.config

The first file is used to define required custom actions for your application (that’s just a regular “instrument.config”). The second file configures statistic counters.

Here is how you can define required custom actions:

<ss:instrumentationAssemblies>
<ss:instrumentationAssembly name=”Agent.StatisticCounters” keyToken=”97bd5f1ee20e650e” version=”5.7.491.0″ locale=”Neutral” />
<ss:instrumentationAssembly name=”CustomActionTest” keyToken=”aa075fad33dac208″ version=”1.0.0.0″ locale=”Neutral” />
</ss:instrumentationAssemblies>
<ss:actions>

<ss:action name=”FunctionStatisticCounter” assembly=”Agent.StatisticCounters” class=”Agent.StatisticCounters.StatisticCounter” method=”SimpleSyncAction” />
<ss:action name=”EntryPointStatisticCounter” assembly=”Agent.StatisticCounters” class=”Agent.StatisticCounters.StatisticCounter” method=”SyncAction” />
</ss:actions>

The difference between FunctionStatisticCounter and EntryPoinstStatisticCounter is that you can use conditions for the entrypoint counters. More on that later, but the idea is that you can use such counters to count the number of particular page calls, for instance, by defining a condition that looks for a substring in the request URL.

Once the custom actions are defined, you need to link them to the application functions:

<ss:applications>
<ss:application name=”w3wp.exe” displayName=”Web Applications” enable=”true” >
<ss:functions>
<ss:function name=”System.Web.UI.Page.ProcessRequest” module=”System.Web.dll”>
<ss:action position=”postfix”/>
</ss:function>
<ss:function name=”ImageCopyrightService.ImageCopyrightHandler.ProcessRequest” module=”ImageCopyrightService.dll”>
<ss:action name=”FunctionStatisticCounter” position=”postfix”/>
</ss:function>
</ss:functions>
</ss:application>
</ss:applications>

Up until this point we did not define instance names for the counters. That should be done in the second file (.StatisticCounters.Action.config). Here is how it may look like:

<?xml version=”1.0″ encoding=”utf-16″?>
<ss:configuration xmlns:ss=”http://AVICode.com/Intercept/Cartridges/StatisticCounterAction”>
<ss:actionSettings>
<ss:applications>
<ss:application name=”w3wp.exe” displayName=”Web Applications” include=”true”>
<ss:functions>
<ss:function name=”System.Web.UI.Page.ProcessRequest”>
<ss:conditions>
<ss:condition name=”defaut page”>
<ss:expression argument=”path” pattern=”/DinnerNow/Default.aspx” />
<ss:action name=”EntryPointStatisticCounter”>
<ss:property name=”instance” value=”DinnerNow Default Page Instance” />
</ss:action>
</ss:condition>
</ss:conditions>
</ss:function>
<ss:function name=”ImageCopyrightService.ImageCopyrightHandler.ProcessRequest”>
<ss:action name=”FunctionStatisticCounter”>
<ss:property name=”instance” value=”ImageCopyrightService Counter” />
</ss:action>
</ss:function>
</ss:functions>
</ss:application>
</ss:applications>
</ss:actionSettings>
</ss:configuration>

Notice the use of “condition/expression” construct for System.Web.UI.Page.ProcessRequest. Being configured this way, EntryPoinstStatisticCounter will count the number of calls for “/DinnerNow/Default.aspx” only, and, as an end result, there will be a performance counters instance called “DinnerNow Default Page Instance”. As to the “functionStatisticCounter”, that part of the configuration is pretty much straightforward. You cannot define conditions for this type of counters.

Once everything is configured, you can restarts IIS and try to open a few aspx pages from Dinner Now (that’s what I used for this exercise). After that, open Windows Reliability Monitor and you should see the following:

Statistic ?ounters

Statistic ?ounters

The counters should be there, and you did not have to code anything to make it work.

Feel free to download sample statistic counters configuration files:

http://gotchahunter.net/gotchahunter/data/samples/AVIcodeCustomActions/StatisticCounters.zip

Please note that you may have to update those files with your applications/function names to make them work for you.

In the next part:

– what you can do with statistic counters in the .NET MP
– why(and how) you may want to change data collection rules for your custom actions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.