IN THIS CHAPTER
The life of an application begins after development, optimization, and deployment. When customers and users access the system’s features and services, they’ll notice its behavior and personality. In some cases, the reasons for a problem or behavior are obvious and you can easily correct or modify them. Other complications are more subtle and harder to understand, track, trace, and log. To track, trace and log, it was once a common practice in ASP-based websites to use print statements for debugging, or to strategically place Response.Write() commands in the file to write algorithm results and to confirm run time values.
Debugging and troubleshooting capabilities have improved greatly with the introduction of such technologies as System.Diagnostics, Tracing, ETW, Logman, Failed Request Tracing, and so on, which are built into the Windows Server environment and require no additional installations. This is important because in many environments security, release, or change management processes prevent you from installing tools and monitors or make it extremely time-consuming to deploy them. When production problems occur, it is important to move fast, so having these features on the platform by default moves debugging and diagnosis along quicker.
If you have completed all the chapters in the book up to now, you have deployed an ASP.NET MVC 4 project onto a Windows Azure Web Site and Cloud Service. If you have not completed all the chapter exercises but still have a website or Web Role on Windows Azure, you might still be asking a valid question: How can you monitor, log, and troubleshoot problems that happen within the application? Troubleshooting and logging capabilities differ between a website and a Web Role. This section discusses these differences and provides details about the troubleshooting features of both.
Windows Azure Web Site has numerous monitoring features that do not require any further modifications or additions to code. You can find these on either the Dashboard or the Azure Web Site’s Console. The reasons for monitoring your system are numerous and include performance fine-tuning and usage forecasting.
A website administrator should always watch for opportunities to improve performance; however, without baseline performance measures, if you implement any change you would not have a performance metric with which to compare against. Therefore, capturing, storing and analyzing baseline metrics is an important part of monitoring.
Monitoring is also useful for forecasting usage and scaling requirements. If a website administrator sees the CPU or memory utilization of the system trending toward 100 percent utilization, he or she must increase the hardware capacity. CPU and memory utilization are both parameters that the administrator can monitor and store via the Windows Azure Dashboard.
This Dashboard provides an overview of some basic metrics. For example, CPU Time, Data In and Out, and HTTP Server Errors are shown, by default, via a graph with the associated value. If you access the Windows Azure management console by clicking Web Sites and then the Dashboard you want to monitor, you’ll see a page similar to that shown in Figure 7-1.
Basic metrics include:
Other than the Dashboard, you have another graph in the Monitor section of the Windows Azure Web Site’s management console. This graph provides additional metrics that you can add by clicking the Add Metrics link at the bottom of the management console page. Selecting this link opens a pop-up menu, as shown in Figure 7-3.
These metrics give you some quick but deeper insight into your website without you needing to download and analyze any logs or traces. Some of the traceable metrics include authentication errors, attempted access to restricted files, requests for files or services that were not found, and server errors. These metrics and graphs are useful; however, if you notice something that doesn’t seem right, like a lot of authentication or server error counts, deeper analysis of the issue is required.
When you identify that there may be a problem on the website and want to dig a little deeper into the problems, you have the following options:
The numerous differences between a Windows Azure Web Site and a Cloud Service have been touched on throughout this book. For example, a website is likely co-hosted on a virtual machine with other websites (a multitenant configuration), while a Cloud Service is hosted on a dedicated virtual machine. Also, a website has only a single production instance, whereas a Cloud Service offers both a production and staging environment. It is possible to create multiple websites and use one for production and another for staging, however there is no built-in capabilities for the promotion of the staging environment to production as exists when using a Cloud Service. The same is true for monitoring capabilities; some features are only available through a Cloud Service.
With the Cloud Service hosted on a virtual machine, the most significant difference and benefit is creating a Remote Desktop Connection. This is useful because you have access to the same tools and features as you would if you’d connected to a virtual machine or an actual physical server. These tools include the Task Manager, the Event Viewer, and any of the many additional features available via the Server Manager Management console.
The Task Manager lets you check the percentage of CPU used per process and the amount of memory the process is consuming. It also supports the creation of a memory dump — useful for troubleshooting hanging or crashing IIS worker processes. The Event Viewer provides access to System and Application logs. These logs can help find a cause of errors encountered during an HTTP request. Each logged event has an associated ID and a source, which you can use to identify a root cause and a possible fix.
Features such as IIS and PowerShell are available when you connect to the Cloud Service, too. In the IIS management console, you can make changes to IIS logging to capture more data or install the Advanced Logging module to increase the level and value of IIS logging. You can also enable and configure Failed Request Tracing logs. These logs provide a deeper insight into the state of IIS and the HTTP request state along the entire request pipeline from start to finish. You can make any modification to IIS on a standalone server or on a virtual machine via the remote connection.
PowerShell also provides features for modifying the configuration of the website hosted on IIS. Any modification you can perform from the IIS Management console can also be performed via PowerShell. For example, the PowerShell command shown in Listing 7-1 can enable IIS Logging on a website named Default Web Site.
LISTING 7-1: PowerShell Example, Enabling IIS Logging
PS C:>Import-Module WebAdministration
PS C:>Set-ItemProperty "IIS:SitesDefault Web Site"
-Name logfile.enabled
-value $True
PowerShell also has a feature for checking the availability or status of the website. By simply navigating to the IIS:Sites directory using common command-line commands such as cd Sites and the dir, the list of websites and their status are rendered.
The Windows Azure Cloud Service management console is similar to the Web Site management console. As shown in Figure 7-5, there are only a number of differences.
From a monitoring perspective, you might notice that the Dashboard has additional links for Production and Staging.
The various timeframes for setting the graph are 1 hour, 24 hours, and 7 days, whereas for a website, the smallest timeframe is 6 hours. Clicking the Monitor link provides the graph shown in Figure 7-6, which contains response times that are generated from endpoints.
As mentioned previously, both Windows Azure Web Sites and Cloud Services support endpoints; however, the website must be in Reserved Mode. For a Cloud Service, the feature is available by default. To enable an endpoint, select the Configure link, and scroll down until you see endpoints in the Monitoring group, as illustrated in Figure 7-7.
The endpoint feature supports the input of up to three locations per two endpoints, which means you can track the Web Role performance and responsiveness from six different locations around the world. When you add this feature, select Save, and moments later the requests are made to the URLs in the endpoint, and the graph shows the results of the requests.
With this option, you can access verbose monitoring from outside of the management portal. When the monitoring level is changed from Minimal to Verbose (refer to Figure 7-7) six tables are created for the Web Role. Two tables are created for each of the following timeframes:
To view the contents of these tables from Visual Studio 2012, follow these steps:
The format of the table is a GUID-like number and the aggregation interval (5M, 1H, or 12H) and role level (R) or role-level instances (RI). Example data stored in the 1HR table is shown in Figure 7-10.
The specific data in table 1HR is configured to store the following metrics on an hourly basis:
You use the data in the tables to create graphs and reports useful for deeper analyses into the performance and stability of the Cloud Service. For example, you can import the data into Excel and create graphs and summaries.
Many of the configurations you make while logged into the online Windows Azure Management Console can also be performed from Visual Studio. For example, right-click the Web Role as shown in Figure 7-11, then click Properties.
By clicking the Properties menu item, a tab opens containing the following options also illustrated in Figure 7-12.
Changes made to the configuration in Visual Studio are applied to the environment when you publish changes or deploy the Web Role to the Windows Azure Platform. Changes are currently not applied automatically.
Viewing diagnostic data in near real-time is possible from Visual Studio. As mentioned previously and illustrated in Figure 7-9, it is possible to connect to the Web Roles’ storage to view and extract diagnostic data. You can find another useful Visual Studio feature on the Diagnostics summary tab. You access this tab by right-clicking the Web Role under the Windows Azure Compute feature in the Server Manager Explorer. This is illustrated with Figure 7-13.
The Diagnostics Summary tab is rendered for the selected Web Role. The contents on the tab refresh every 15 minutes or you can refresh it manually by clicking the Refresh button. The Diagnostics summary tab is illustrated with Figure 7-14.
The standard tools and features available in the Windows Azure management console give administrators a valuable and clear overview of the performance, availability, and stability of their website or Web Role. However, numerous third-party tools are also available, and they give you additional capabilities for monitoring your solution on Windows Azure. Third-party tools for remote administration, computer usage monitoring, billing monitors, and storage management tools are available.
The open source tools in the following list are projects that are created, driven, and supported by the community using them. Open source tools, applications, and libraries generally have no formal support. Instead, administrators get their support from online forums. In many cases, a project team manages bug changes and new feature requests so that the code-base remains stable. Because these are open source tools, companies or individuals can branch the source and implement new features or fix bugs themselves.
The Windows Azure Service Management API provides REST and .NET API resources that provide programmatic access to most of the functionality available from the Windows Azure management console. For example, creating a storage account, creating a cloud service, or creating and managing a virtual machine can all be performed via REST or a .NET API.
You can find more information about these capabilities at the following locations:
The .NET Class Libraries currently have three namespaces:
These namespaces provide a developer with a library for creating and managing diagnostics from with the application’s code. For example, there is a class named CrashDumps that triggers the creation of a memory dump of a crashed or hung process. The memory dump can later be downloaded and analyzed to find and resolve application issues.
PowerShell is a powerful scripting language that Windows system administrators must know. The capabilities that PowerShell cmdlets provide continue to grow and give administrators options for managing and monitoring almost all features on the Windows platform.
Cmdlets fall into two broad categories:
Both groups support remote execution. This means you can administer your Windows Azure Web Site, Web Role, and database from a workstation. To set up PowerShell for remote execution of Windows Azure cmdlets, you need to perform the following three commands shown in Listing 7-2.
LISTING 7-2: Setting Up Remote PowerShell to Exeute Azure Cmdlets
PS C:>Set-ExecutionPolicy RemoteSigned
PS C:>Import-Module "C:Program Files (x86)Microsoft SDKs
Windows AzurePowerShell
AzureAzure.psd1"
PS C:>Get-AzureSubscription
If you have multiple subscriptions, use the Set-AzureSubscription cmdlet so that the actions taken using PowerShell are applied to the intended subscription. There are many Windows Azure PowerShell cmdlets. To get a list of them, enter the command shown in Listing 7-3.
LISTING 7-3: Listing Windows Azure PowerShell CmdLets
PS C:>get-help Azure
The result of the command executed in Listing 7-3 shows all existing Windows Azure PowerShell cmdlets. Any action available from the Windows Azure Management Console can be performed using a PowerShell cmdlet. These cmdlets can be used for, but not limited to:
The following list contains monitoring tools created by Microsoft. You can download and use them with that confidence that they work in tight side-by-side grouping with any existing component installed on your system.
In this chapter, you learned about the different monitoring options available on the Windows Azure platform. You learned some capability differences between a Windows Azure Web Site and a Web Role. For examples, although endpoints are available in both cases, you must place the website in Reserved mode for it to be configurable. Also, a Remote Desktop Connection is only possible with a Web Role. By connecting to the Web Role using Remote Desktop Connection, tools are available for troubleshooting many issues.
You also have access to numerous tools — such as PowerShell, open source, and third-party applications — for monitoring and remotely managing an application hosted on the Windows Azure platform. Chapter 8 contains exercises that illustrate many of the concepts discussed in this chapter.