ASP.NET application health and performance are often solely measured via the metrics provided by the server hardware it’s being run on. While server hardware does have a large impact on the overall health of a system, it barely scratches the surface of the health of the actual application. It is crucial that you monitor and instrument both hardware and software aspects of a system so that you can attain the system’s overall health. This article will focus on monitoring ASP.NET application software, as well as demystifying what aspects of an application should be instrumented and why.
Exceptions
Let’s start with the most obvious indicator of the health of an ASP.NET application: exceptions. Exceptions occur when something has gone wrong within the application. It is already a common development practice to log exceptions within an application. These exception logs can take on many forms. The most common are having the log live directly on the server in a file, or within the Windows Event Viewer. Other times, you could use a logging database, or the application could leverage some type of third-party logging service. In most cases, the code that logs these exceptions needs to be manually added at the development time, and relies upon the developer to ensure its completeness and correctness.
Try:
{
int denominator = 0;
int x = 299 / denominator;
}
catch (Exception ex)
{
Logger.LogException(ex);
}
Reviewing exception logs provides information to gauge where bugs are occurring within the application. This approach tends to be reactive, meaning that it often takes end-users reporting problems for developers to be made aware of the issue and begin sifting through logs to find it. Depending on the quality of the log entry, further investigation and communication with the end-user could be required to assess the full picture of the defect, recreate the issue, and mitigate it.
Exception monitoring is important to identify problem areas in an application and obtain relevant data so that it can be fixed appropriately.
Latency
A positive user experience is one of the top qualitative requirements for an ASP.NET application. If page load times and action processing times seem to be slow, they impact the overall experience of the end-user. Each action or page load may interface with assorted libraries, web service invocations, and database calls. As such, there are many facets you would need to analyze to identify the root cause of poor performance.
There are multiple ways to approach monitoring latency in an ASP.NET application. One could introduce timers into the source code and log them appropriately. Alternatively, you could utilize a third-party service to introspect code paths through the call stack to the database call and back to the end-user. It is also important to note that blame doesn’t always fall on unoptimized code or bad SQL queries; latency can also be introduced via static content like images and non-streamed video.
Stopwatch timer = new Stopwatch();
timer.Start();
Thread.Sleep(3000);
timer.Stop();
Logger.LogInfo($"XYZ Controller, Index Action, {timer.Elapsed.Milliseconds} Milliseconds");
As mentioned above, latency monitoring of an ASP.NET application is important to ensure a good user experience. It is also important in the case of Service Level Agreements (SLAs). If you deliver a Software as a Service (SaaS) solution, part of the contract typically deals with a Requests Per Second or Pages Per Second requirement that must be met as part of the contract. Failure to do so would result in lost revenue and possibly lost clientele.
End-User Analytics
Above and beyond determining the stability and health of an ASP.NET system, there are also other benefits to having a good application monitoring solution in place. The largest benefit is getting to better know the end-user population.
One benefit to cloud-based solutions is the ability to capture end-users’ geography to identify different parts of the world where application servers should be deployed. Another benefit is the ability to analyze the usage of different features within the application. This serves as a definitive guide in determining which bug fixes should take priority, and provides insight into which application features should be prioritized for future enhancements.