Procedure for Manually Applying Custom Instrumentation to Un-instrumented Methods in .NET Applications under the .NET Agent
APM Insight .NET Agent automatically instruments the .NET framework related methods and collect the metrics. Custom instrumentation helps to view your own framework performance without changing your application code. It allows you to track your own application methods captured and displayed in the transaction traces. It will be helpful to identify the performance related issue, when you suspect the execution time is taken more by your own application method.
If your application has a method with large code blocks or it has some external calls, custom instrumentation helps you to identify the root cause of the performance issue.
Note: There are no restrictions on the number of methods that can be configured manually. You can configure more than 2000 methods, but only the first 2000 will be tracked and monitored. If the process is recycled, the instrumentation will be reset, and only the first 2000 methods will remain instrumented. Benefits
- Viewing your own framework or web application performance.
- To group method metrics/performance, we can name same component for multiple methods. For Example:
- Method1 : SampleComponent
- Method2 : SampleComponent
- Method3 : SampleComponent
- Note: If the SampleComponent takes 25% time in overall application, it means that the three methods defined for the component consumed 25% of overall performance.
- Tracking performance of any third party framework used in your application.
Configuring custom instrumentation
The data in the configuration file as defined by APM Insight is in json format. We can define the assembly name, class name and method name used in your own web application and also we can specify the component name for each methods. The agent reads the configured data and track the performance of the methods specified.
The custom instrumentation configuration file `custom_instrumentation.json` can be found in `C:\ProgramData\DotNetAgent` path.
Syntax of the Custom Instrumentation data:
- {
- "AssemblyName1": {
- "NameSpace.ClassName1": {
- "MethodName1": "ComponentName"
- },
- "NameSpace.ClassName2": {
- "MethodName1": "ComponentName",
- "MethodName2": "ComponentName"
- }
- },
- "AssemblyName2": {
- "NameSpace.ClassName1": {
- "*": "ComponentName"
- },
- "NameSpace.*": {
- "MethodName1": "ComponentName",
- "MethodName2": "ComponentName"
- }
- }
- }
Where,
- AssemblyName: Name of the DLL.
- NameSpace.ClassName: Name of the Class including the namespace name.
- MethodName: Name of the method to be monitored.
- ComponentName: Component name for the method. If it is empty, the component name will be taken as POCO(Plain Old CLR Object) by default.
Note: Providing * in place of ClassName or MethodName, will track all the methods in the classes of assembly. We need to add `enable.wildcardmatch=true` in `C:\ProgramData\DotNetAgent\apminsight.conf` file and restarting the `ManageEngine .NET Agent` to achieve this. Custom instrumentation example:
In the following code sample, we use employee DLL which has a controller class, SalaryController, containing three methods.
- namespace Employee.Controllers
- {
- public class SalaryController : Controller
- {
- public ActionResult ProcessPayRoll()
- {
- EmployeeSR.EmpServiceClient empServiceClient = new EmployeeSR.EmpServiceClient();
- empServiceClient.ProcessPayroll(Context.EmpId);
- return View();
- }
- public ActionResult GetSalaryAmount(int empId)
- {
- using(var conn = new SqlConnection(connString))
- {
- conn.Open();
- var cmd = new SqlCommand("select Salary from Employee where id='" + id + "'", conn);
- ViewBag.SalaryAmount = cmd. ExecuteScalar();
- conn.Close();
- }
- return View();
- }
- public ActionResult GetSalaryPerMonth(string id)
- {
- int salary = GetSalaryPerYear();
- ViewBag.Result = salary / 12;
- return View();
- }
- }
- }
The custom instrumentation configuration for the class as follows,
- {
- "Employee": {
- "Employee.Controllers.SalaryController": {
- "ProcessPayRoll": "PAYROLL",
- "GetSalaryAmount": "FETCH",
- "GetSalaryPerMonth": "FETCH"
- }
- }
- }
The instrumented methods will be displayed with execution time under the APM -> Your APM App/Instance -> Traces Tab -> Graph View -> Traces Details.
Note:
- No need to restart IIS.
- We need to recycle the corresponding application pool after modifying the custom instrumentation file to take effect.
New to ADSelfService Plus?