Chapter 7

Maintaining an ASP.NET MVC 4 Deployment on Windows Azure

CONCEPTS

IN THIS CHAPTER

  • How to monitor a Windows Azure Web Site
  • How to monitor a Windows Azure Cloud Service
  • How to use Windows Azure tools

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.

MONITORING A WINDOWS AZURE WEB SITE

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.

Monitoring with the 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:

  • Relative versus absolute: You can change the graph properties to show relative versus absolute values. When the Absolute option is selected, the Y-axis values display, and the graph is modified so that the values of the metrics drive the graph instead of the relative relationship between the metrics value. See Figure 7-2 as an example and compare it to Figure 7-1.
As you can see in Figure 7-2, the values are graphed by the measured value of the metric instead of the relative value.
  • Changing the Timeframe: You can also change the time frame of the graph from 6 hours, 24 hours, and 7 days by selecting the desired value from the drop-down located on the top-right of the graph shown previously in Figure 7-2. This provides the administrator with a quick view of the overall current and historical usage and health of the website.

Monitoring with the Website’s Management Console

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:

  • Application Logging (File System). This is similar to the Application Event logging that is commonly accessed through the Event Viewer. The logging level is configurable so that only error, warning, information or verbose errors are logged. This log provides time, date, an Event ID, a stack dump, and often the specific component that caused the event to be logged. This information is useful when you’re debugging any issue.
  • Application Logging (Storage). Similar to the Application Logging (File System) feature, but instead the logs are written to a storage account so that the data can be accessed remotely using a database connection string. You can apply filters to the data as well as create pivot tables to make the website performance analysis simpler to track and monitor.
  • Site Diagnostics. This section contains three logging capabilities that you can enable or disable from either the Windows Azure Management console or from within Visual Studio:
    • Web Server Logging log: Similar to the IIS log that saves requests in the W3C extended file format. This log file contains dates, times, IP addresses, port numbers, HTTP verbs, file names, files sizes, and HTTP statuses to name a few — all of which are useful pieces of information.
    • Detailed Error Message logs: These are .HTM files similar to that shown in Figure 7-4. The file contains the name of the file requested, the likely cause of the error, and some possible solutions.
    • Failed Request Tracing: Introduced in IIS 7, this feature provides a detailed log of a request as it flows through the integrated pipeline. With it, you can see when modules load in IIS, when authentication happens, when the page loads, when the page is complete, and everything in between. This log is not only helpful in identifying a specific error, but also in determining when the website is performing slowly. You can use timings logs at each stage of the process to find the exact point where the time expended is the greatest.
  • Endpoint feature: This feature checks the responsiveness and availability of your website from numerous locations around the world. Endpoints are available with Windows Azure Web Site, but only when you’re in Reserved mode, where all your websites run on a dedicated virtual machine. This feature is available in all Windows Azure Cloud Services, and more details are provided about this feature in the next section.

MONITORING A WINDOWS AZURE CLOUD SERVICE

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.

Using the Task Manager and Event Viewer

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.

Using IIS and PowerShell

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.


NOTE If you have scaled your worker instances and you make a change to one of the IIS instances, those changes are not replicated to the other instances automatically. Therefore, consider getting a single instance the way you need it before increasing the instances.

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.

Using the Cloud Service Management Console

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.

Production and Dashboard Links

From a monitoring perspective, you might notice that the Dashboard has additional links for Production and Staging.

Timeframe

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.

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.

Endpoint Locations

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.


NOTE Note that this feature is available in Preview mode; therefore, the limits may change at some point in the future.

Verbose Monitoring

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:

  • 5 Minutes
  • 1 Hour
  • 12 Hours

To view the contents of these tables from Visual Studio 2012, follow these steps:

1. Expand the Server Explorer, and click Windows Azure Storage, as shown in Figure 7-8.
2. Enter the credentials found in the Diagnostics Connection Strings (refer to Figure 7-7). An example of the values follows:
  • DefaultEndpointsProtocol=https
  • AccountName=hitman
  • AccountKey=ahAyTA****1hQyEEgLViOewk*****SVZEDhVJD+e2kK0CQaKrXRXckk uYo8S4+4/74******

NOTE The Windows Azure SDK for Visual Studio 2012 must be installed for the Windows Azure Storage option to be available. For more information, see Chapter 6.

3. After the connection is made, you can expand the Tables listing by clicking the Account Name and then ⇒ Tables. The tables containing the verbose data are rendered, as shown in Figure 7-9.

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:

  • ASP.NET Applications(_Total_)Errors Total/Sec
  • ASP.NET Applications(_Total_)Requests/Sec
  • ASP.NETRequests Queued
  • ASP.NETRequests Rejected
  • MemoryAvailable Mbytes

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.

Configure a Cloud Service from Visual Studio

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.

  • Configuration: Supports scaling, VM Size, enabling and disabling HTTP endpoints, and diagnostics.
  • Settings: An interface for adding settings or modifying existing settings like:
    • Diagnostics.ConnectionString
    • RemoteAccess.Enabled
    • RemoteAccess.AccountUsername
    • RemoteAccess.AccountEncryptedPassword
    • RemoteAccess.AccountExpiration
    • RemoteForwarder.Enabled
    • Caching.NamedCaches
    • Caching.DiagnosticLevel
    • Caching.CacheSizePercentage
    • Caching.ConfigStoreConnectionString
  • Endpoints: For adding and updating endpoints for performance monitoring.
  • Local Storage: For adding a local storage to be used by the diagnostics capabilities.
  • Certificates. For adding or updating certificates.
  • Virtual Networks. Useful for management and administration of Virtual Networks hosted on the Windows Azure platform.
  • Caching. For enabling, disabling and configuring caching.

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.

Monitor a Cloud Service from within Visual Studio

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.

MANAGEMENT AND MONITORING TOOLS FOR WINDOWS AZURE

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.


NOTE The cloud space is changing at a rapid pace. Therefore, the links, tools, and features provided in this section may be out of date rather quickly. You can learn more about the most current tools by performing a quick Bing or Google search for Windows Azure Monitoring Tools.

Open Source Tools

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.

  • Windows Azure Platform Management Tool (MMC): Helps you easily manage your Windows Azure-hosted services and storage accounts. This tool comes as a sample with complete source code, so you can see how to perform various management and configuration tasks using the Windows Azure Management and Diagnostics APIs. For more information, see http://wapmmc.codeplex.com/.
  • Windows Azure Diagnostics Monitor: A sample application that enables you to view and analyze basic Windows Azure Diagnostics information using a simple web interface. Visit: http://archive.msdn.microsoft.com/wazdmon.
  • Azure Application Monitor: Helps you monitor your Azure-hosted applications in real time. It includes a library for capturing run time process information to cloud table storage, and also a desktop application for viewing the captured information in real time. For more information, see: http://azuremonitor.codeplex.com/.
  • Cloud Ninja: This is a Windows Azure multitenant sample application demonstrating metering and automated scaling concepts. It also has some common multitenant features, such as automated provisioning and federated identity. For more information, see: http://cloudninja.codeplex.com/.
  • Cloud Samurai: Also called Project Bowlus, this is a complete code sample demonstrating a hosted multitenant approach on Windows Azure utilizing the IIS Application Request Routing (ARR) extension. You can see this at: http://cloudsamurai.codeplex.com/.
  • Azure Storage Explorer: A useful GUI tool for inspecting and altering the data in your Windows Azure Storage. Storage projects include the logs of your cloud-hosted applications. For more details, visit: http://azurestorageexplorer.codeplex.com/.

Windows Azure Management API

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:

  • Microsoft.WindowsAzure.Diagnostics
  • Microsoft.WindowsAzure.Diagnostics.Management
  • Microsoft.WindowsAzure.ServerRuntime

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.

Windows Azure PowerShell Cmdlets

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.


NOTE You can find information about Windows Azure PowerShell cmdlets here: http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx.

Cmdlets fall into two broad categories:

  • For performing actions primarily in the management console. These include those for managing your subscription, deploying and managing virtual machines, managing Virtual Networks, managing storage accounts, and deploying and managing Cloud Services.
  • For managing a SQL database hosted on the Windows Azure platform. These provide capabilities for managing SQL server firewall rules and adding and removing a SQL server database.

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

NOTE If you are running on a 64-bit workstation, instead of importing the Azure.psd1 in the Program Files(x86) directory, import the one in the Program Files directory.

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:

  • Managing Cloud Services
  • Setting up and managing virtual machines
  • Managing storage, images, and disks
  • Managing certificates and SSH keys
  • Creating and deleting websites

Microsoft Tools for Monitoring and Managing Windows Azure

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.

SUMMARY

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset