NMonitoring Pointcuts creation

The application will be monitored by aspects. Those aspects will record statistics and log them to database (or other output)

NMonitoring library has a base class for doing that: the PerformanceAspect class.
This class could not be used directly as it did not provide a method that could be used a valid aspect for AspectDNG.

So the first step will be to create a new class that inherits from PerformanceAspect, in a C# Class Library.

 
namespace sample_aspects
{
    public class SampleAspect : Org.NMonitoring.Core.Aspect.PerformanceAspect 
    {
    }
}

Then we will add a method that has a suitable signature for AspectDNG. Let?s say that we want to intercept all access to Execute method from System.Data.SqlCommand. We will then add a ?SqlExectuteAspect? that will call the ExecutionToLogInternal method (defined in the PerformanceAspect base class)

 
namespace sample_aspects
{
    public class SampleAspect : Org.NMonitoring.Core.Aspect.PerformanceAspect 
    {
	public static object SqlExectuteAspect(OperationJoinPoint jp)
        {
           return Org.NMonitoring.Core.Aspect.PerformanceAspect.ExecutionToLogInternal(jp);
        }
    }
}

ExecutionToLogInternal use two members:

  • GroupName, that defines a logical group in which method call could be merged
  • LogParameter (default=false) that defines if NMonitoring has to store the method?s parameters

So, in our example we will group the methods intercepted by our Aspect in a ?SQL? group and we won?t log the parameters. Our aspect class become:

 
namespace sample_aspects
{
    public class SampleAspect : Org.NMonitoring.Core.Aspect.PerformanceAspect 
    {
	public static object SqlExectuteAspect(OperationJoinPoint jp)
        {

            GroupName = "GpeItem";
            LogParameter = false;  // Default setting
           return Org.NMonitoring.Core.Aspect.PerformanceAspect.ExecutionToLogInternal(jp);
        }
    }
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.