Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Remote debugging App Service using visual Studio, monitoring and configuring alerts: Part 3

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

  1. Remote debugging App Service using visual Studio, monitoring and configuring alerts

We have successfully configured the deployment slot in previous post, now we are going for remote debugging. In Azure remote debugging using visual Studio is not enabled by default, you have to enable debugging for specific VS version to debug. Although if you have permissions you can do it by Visual Studio if you do not have enough permissions, please ask your Azure Subscription owner. In our case we are the owner of Azure Subscription so we will proceed for debugging with out requiring any permissions,

If you have not already opened your visual studio, then open it and load the project you had deployed earlier. Now go to Cloud Explorer | your subscription | Select your app | Actions | Click on Attach debugger.

Figure 1 Remote Debugging

Debugger will be attached, it may take some time depending upon your internet connection speed and your location distance to Azure Data center, If you are getting error like below, that means you do not have permissions to debug or you have not enabled Debugging for your App Service, remember by default debugging is not enabled. In my case, it was referring to firewall settings and we found out that there were some ports closed which needed to be opened to communicate with Azure.

Figure 2 Error While connecting to Remote Debugging Session

Go to Azure Portal and then App Service | Settings | Application Settings | Debugging | enable Remote debugging and also choose visual studio version and click save. Now by this step your debugger should be attached successfully.

Figure 3 Enabling Remote Debugging

If you still not able to resolve the problem please consult my recent post which discuss the steps to fix common debugging issues.

Also check Microsoft page

Once you are in debugging mode, you can use all the tools that you use while debugging locally.

App Service Monitoring

Let us move on to monitoring our App Service.

Azure provide you multiple ways to monitor your App Service, Let us explore them, go to Azure Portal and then App Service | Overview, in this view you can see the basic information about http errors, data in, data out, number of requests and Average response time. All though this view will satisfy most users, but you can even drill down and generate custom views for you as well, just click on any of the chart and you will see a new view, in which you can tailor the chart according to your metrics.

Figure 4 Monitoring performance

For demo, We have added CPU Time into the mix, and we can see that display show both Average Response Time and CPU Time as well.

Figure 5 Create Custom chart

You can click on Pin to dashboard to see it on your main dashboard as well.

Figure 6 Pin to dashboard

Alerts

This bring us to our next topic alerts, alerts can be very useful especially when you have a lot of resources and do not have time to manually check the metrics to see what is going on. We can create alert right on a particular metric by clicking on

Or App Service | Monitoring | Alerts

Let us create an alert on CPU Percentage on our App service Plan ( it will include all the apps hosting on same App Service Plan) and choose CPU Percentage and set condition to “greater than” and threshold to 80. You will notice that the chart shows you current CPU percentage in dotted line and the threshold in straight line, do not forget to check email owners check box if you are the owner and want to get the alert email otherwise there is a textbox to add addition emails or call a webhook. Webhook is a restful endpoint, which is publically accessible to Azure and will be called when metric pass the condition we set. Mostly developer use webhook to initiate a workflow, which could for example increase number of running instances through PowerShell script or initiate a business workflow. To learn more about webhook see https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts

Figure 7 Create alert on CPU percentage for App Service Plan

As you, can see that I have created two alerts, one for CPU percentage and another for Memory percentage. Now when ever condition you set will meet you will get an email or a webhook will be called. Alerts truly simplify our monitoring task specially if we have a lot of resources to worry about.

Figure 8 Create Alert on CPU and Memory percentage

Congratulations, you have successfully debugged and monitored your application and configured alerts.

Coming up next Diagnostic logs, live stream, process explorer and KUDU

 

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK: Part 2

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK

At this point, you have successfully created the App Service Plan, App service and published the changes to the Azure using Visual Studio and Azure SDK. Let us move to exciting part of remote debugging and monitoring, fire up your visual studio if you have not opened it before and open the project we created in recently.

Figure 1 App Service Deployment Slot

Let us talk about Deployment Slot, this is feature provided by App service, this basically enable you to deploy your code to different containers i.e. QA, Staging or Production, in this way you will make sure that your code is fully tested and ready to move to production. This approach support setting up different App Settings and connection strings for the Databases for each slot, which will enable us to test and deploy our changing with ease.

I know you are excited about this feature lets, let us open web.config and add a new App Setting

<add
key=WelcomeMsg
value=Welcome to Azure Development!/>

Figure 2 Add new App settings in web.config

Now show this setting in our index page, Views | Home | Index.cshtml and edit it as shown below:

@using System.Web.Configuration;

@{

ViewBag.Title = “Home Page”;

}

<div
class=”jumbotron”>


<h1>ASP.NET</h1>


<p
class=”lead”>@WebConfigurationManager.AppSettings[“WelcomeMsg”]</p>


<p><a
href=”https://asp.net&#8221;
class=”btn btn-primary btn-lg”>Learn more &raquo;</a></p>

</div>

Figure 3 Edit Index file

Now after this change just press F5 to lunch and see the change.

Figure 4 App setting message is showing

Now publish your solution to the Azure App service as we did in our previous post. You can see that new changes publish.

Figure 5 Publishing Changes to Azure App Service

We will override the changes in our App Service Settings; go to Azure Portal and then App Service | Settings | Application Settings, here we will add the key and value to override the default one, please note that we can also use this interface to add new keys as well, this interface is not limited to just overriding key values.

Figure 6 Override Application Settings in Azure Portal

Now refresh to see that message is changed as expected.

Figure 7 Override setting display

Now let us create slots for staging slot. Go to Azure Portal and then App Service, Deployment | Deployment Slots | Click Add Slot and name it as staging, in configuration Source choose the main app and click ok. It could take few minutes depending upon application size.

Figure 8 Add new Staging Deployment Slot

Once deployment slot is added successfully, click on it to see the settings.

Figure 9 Deployment Slot is added successfully.

Change the “WelcomeMsg” to “Welcome message from staging” and tick “slot setting” check box, as when we swap this deployment slot with production this setting will not move and will stay with this slot. This way we will be able to retain the settings that are slot specific.

Figure 10 Change App settings on Staging Deployment Slot

Now question arise how we are going to deploy our source code to staging slot, the answer is very simple Publish Profile, click on Over view and then click on Get Publish Profile and save it to local system.

Figure 11 Get Publish Profile Setting

Go back to visual studio | Publish and click on Create new profile, select Existing check box, click on import profile, click ok, select the staging profile that we got in previous step and click ok.

Figure 12 Import Profile

Figure 13 Import profile and publish

For testing purposes open Index.cshtml file and update it as below

<p
class=”lead”>We have update the project</p>

Figure 14 Update for staging

Publish the changes to staging slot by just clicking on publish; we can see that our recent changes have been published successfully.

Figure 15 Publish changes to staging slot

All these steps lead us to the exciting part of Deployment Slot Swap, Go to Azure Portal and then App Service, click on swap and click ok.

Figure 16 Slot Swap

Figure 17 Choose Swap Slot

Swapping operation will take some time to complete, in side-by-side comparison you can see that staging code is swapped to production and production code is swapped to staging. Remember that user will be experience any downtime in this operation will continue to use the application as they were before swap.

Figure 18 Production and Staging slot swapping

With this congratulation, you have successfully created new staging slot, deployed your code to staging slot, used sticky slot settings, and swapped production with staging.

Coming up next Remote debugging App Service using visual Studio, monitoring and configuring alerts

 

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Solved: The Visual Studio 2017 Remote Debugger (MSVSMON.EXE) does not appear to be running


Errors:

The Visual Studio 2017 Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. This may be because a firewall is preventing communication to the remote computer

Specific method is not supported

Full Detail:

System.Runtime.InteropServices.COMException (0x89710023): Unable to connect to the Microsoft Visual Studio Remote Debugger named ‘scientistzwebapp.azurewebsites.net’. The Visual Studio 2017 Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. This may be because a firewall is preventing communication to the remote computer. Please see Help for assistance on configuring remote debugging.

at Microsoft.VisualStudio.Debugger.Interop.Internal.IDebuggerInternal120.ConnectToServer(String szServerName, VsDebugRemoteConnectOptions[] pConnectOptions, CONNECT_REASON ConnectReason, Int32 fIncrementUsageCount, IDebugCoreServer3& ppServer)

at Microsoft.VisualStudio.Web.Azure.MicrosoftWeb.Operations.RemoteDiagnosticsSessionBase.ConnectToServer(String site, String user, String password)

When it Happen:

If you are using Azure App Service for your application development or deployment, there are some time when you need to debug the solution, Azure provide you the feature of remote debugging. All you need to do is to Attach Debugger and Visual Studio will take care the rest for you.

Figure 1 Remote Debugging on Azure App Service

Sometimes you are not so lucky, and get the error like below:

Figure 2 The Visual Studio 2017 Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. This may be because a firewall is preventing communication to the remote computer

Figure 3 Specific method is not supported.

Solutions:

  1. First, you need to check if you have appropriate permissions on the Web App to do the debugging.
  2. Manually enable the debugging on Web App and try again for debugging.

Figure 4 enable Debugging on the App Service

  1. Make sure that you have published the files in debug mode.

Figure 5 Publish web app in debug mode

  1. Make sure that you are debugging in the right CPU configuration for platform is either x86 or x64, check both on Azure and Visual studio and Match the configuration.

Figure 6 Platform setting

Project | Properties | Build | Platform target

Figure 7 Visual Studio debug Platform target

  1. If you are still getting the issue, this mean there is some firewall or system setting, which is blocking your connection to the debugging service. In order to make sure, let us use Microsoft tool TCPView. When you run this tool and try to remote debug, you will see that devenv.exe (visual studio process name) is trying to connect on port 4022 to Azure IP Address but could not send any packets. This is our problem, all we need to do is to enable this port in our firewall as outgoing and debugging will work just fine.

Figure 8 TCPview to get the Process port communication

Different versions of visual studio have different ports and if you debugging in x64 mode VS2017 will use 4022 and if you are debugging in x86 then VS2017 will use 4023.

Please find below table to find out appropriate port to open in firewall.

https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugger-port-assignments

Version X64 X86
Visual Studio 2017 4022 4023
Visual Studio 2015 4020 4021
Visual Studio 2013 4018 4019
Visual Studio 2012 4016 4020

In addition to this, we need to open

Version Port
Remote Debugger Discovery 3702

More information on windows firewall configuration https://docs.microsoft.com/en-us/visualstudio/debugger/configure-the-windows-firewall-for-remote-debugging

If you are looking for more resources check below link:

https://docs.microsoft.com/en-us/azure/app-service/web-sites-dotnet-troubleshoot-visual-studio