Greetings Foglighter's,
Today I have an add-on to the Foglight 5 .NET cartridge for you that will help you monitor the memory usage of your .NET applications.
Your .NET code runs in Microsoft's Common Language Runtime (or CLR). This engine can provide statistics on its heap usage, just as a Java JVM can do. Foglight 5's .NET agent is able to collect this heap usage information for traced instances of .NET Request Types. In order for Foglight to see this information, you'll need to make sure that the Windows host or VM where the CLR is running has been configured to surface the proper Performance Counters. One easy way to do this is with the perfmon tool. You can launch perfmon from any Windows command prompt, or from Start -> Run. Once perfmon is up, you can check the Performance Counters that are currently surfaced, and add the .NET CLR Memory counters if they are not present:
Once you know this information is present you can deploy the cartridge which is attached to this article. Remember that you'll need to already be using the Foglight 5 .NET cartridge. The add-on was built and tested assuming the presence of version 5.6.6 of our .NET cartridge.
The add-on installs the following entities:
1. A derived metric called NETRequestAllTracesClrMemoryUsedInAllHeaps. This is a calculation which looks up all recorded performance traces of a given .NET Request Type and produces an average value for the .NET Performance Counter called Bytes in all heaps (which is hung off the .NET CLR Memory performance object).
2. A second derived metric called NETRequestLatestTraceClrMemoryUsedInAllHeaps. This derived metric finds the most recent performance trace of a given .NET Request Type, and produces the Bytes in all heaps data for this trace.
3. A rule called NETRequestMemoryDeviation that compares the value of these two metrics and alarms if their difference is greater than some threshold, which in this case is the value of a Foglight Registry Variable called .NETRequestTraceMemoryDeviationWarning, which the cartridge also installs.
Here's a sample alarm generated by this rule:
The rule functions by making a very simple calculation: the difference between the values of NETRequestLatestTraceClrMemoryUsedInAllHeaps and NETRequestAllTracesClrMemoryUsedInAllHeaps. Of course, it would be straightforward to create more sophisticated calculations such as running averages, baselines, standard deviation calculations, trend analysis, etc. For the time being anyway, I'll leave these as exercises for the reader. :-)
Visualizing this data can be very informative. Here's a quick drag & drop dashboard that shows the two metrics graphed together for a few representative .NET Requests:
That's it for now. I hope you enjoy this add-on and as usual, please post if you have questions.
Robert Statsinger
(Please visit the site to view this file)