Configure Azure Public Load Balancer Part -2

This is part-2 of previous article and we are configuring a public load balancer in Azure which for distributing/load balancing traffic between VMs where we host an application or service.

Please read Part-1 before going through steps in this article.

In Part-1 lab, we have added two VMs (Windows Server 2016), specified Virtual Network, configured Availability sets and their public IPs. We also did setup and deploy a web application on IIS in both VMs and tested accessing those using individual URLs.

In Azure portal, add a load balancer as shown below:


Choose the type of load balancer as “Public”



Next step is to select new Load Balancer that is created and go to “Front end IP configuration” and add a public IP address. Note that once completed, we will be using this IP address for accessing the web application (MyWebApp that we created in Part-1 lab) instead of individual IPs for VMs.



Select “Backend Pools” next and click “Add”. Select your availability set where both of our VMs are associated.




Now you will be able to associate  both VMs to the backend pool of load balancer as shown below.


Once done, go to Health Probes, and add a health probe for this load balancer with default settings.

The next important step is to set Load balancing rules. Add one as shown below.



Go to LoadBalancer Front End and you can find the public IP address has been associated and configuration is looking good



Now it is time to test accessing your web application. Note that we access the web application using  LoadBalancer public IP.

http://<load balancer IP address>/MyWebApp

The demo below shows the results when I accessed it using two browser instances. Loadbalancer directed one to VM1 and the other to VM2



Assume that one of your Virtual Machine is down or under maintenance, the load balancer auromatically redirects the traffic to other available VMs. In our case, I have stopped VM1 (WebServerVM1) to simulate such a scenario.


Once VM is stopped, refresh the browser instance which was loaded from that VM1. Note that the load balancer redirects the request to VM2 as shown below.


Details of internal load balancing scenarios will be discussed in another article.


Configure Azure Public Load Balancer Part -1

It has been several months since I covered Azure topics here. As we revisit Azure, I would like to start with Load Balancer.


Microsoft Azure provides load balancer options for the following :

  • Load balance external traffic to your VMs (Public Load Balancer or External Load Balancer)
  • Load balance traffic inside your Azure virtual network (Internal Load Balancer)
  • Port forward traffic to a specific port on specific VMs

Note : If you are looking for how to distribute traffic between different data centers/regions, explore Azure Traffic Manager.

In this article, we will configure an external load balancer. This requires you to create couple of VMs in your Azure account and configure IIS and a web applicationon it first, which is covered in Part-1 here.

First create two VMs. In this case, I selected Windows Server 2016. I named them as WebServerVM1, WebServerVM2



Create an availability set as shown below:


Create Virtual Network (or use an existing one), and create and assign a public IP for both VMs. As shown below, now we have the VMs and the related resources created.


Next step is to remote (RDP) to both VMs. Then install and configure IIS on both using Server Manager.




On each VMs, add inbound rule in Windows Firewall to allow port 80.


Create demo application in IIS (named as MyWebApp in this example) on both VMs and place a simple HTML file as home page. For our demo, I added a text in html home page content to identify whether it is deployed in VM1 or VM2.


This completes our VM and application configuration on both VMs.

Going back to Azure portal; we also need to set Inbound Security Rule in Network Security Group for both VMs.

  • Select NSG resource.
  • Click on Inbound Security Rules
  • Add rule for port 80 as shown below


Once this is completed, you can access applications on both VMs using their individual URLs using their public IPs as demonstrated below.


Next step is to configure our public load balancer for these two VMs. We will explore that in our next lab/article.




Save the date for Microsoft Azure OpenDev virtual event


Azure OpenDev, the first-ever virtual event from Microsoft that showcases open source technologies in the cloud.

Hosted by John Gossman, Lead Architect, Microsoft Azure, the event features industry thought leaders including Mark Shuttleworth of Canonical and speakers from Docker, Pivotal, Red Hat, and Chef—as well as Microsoft teams dedicated to open source. Hear from customers such as Mastercard about solutions they’ve built with open source that run on Azure today.

Join online to learn how to:

  • Use containers to build microservice-based solutions on Azure, in Java, Node.js, and more.
  • Use existing open source skills and tools to enable your DevOps pipeline in the cloud.
  • Modernize your existing apps and implement community best practices.

Have your questions answered by subject matter experts in a live Q&A, and participate in hands-on sessions with open source on Azure.

Save the date

Configure Puppet Enterprise master and agent for your Azure VMs

In my previous blog, we have seen usage of DSC scripts to install and maintain configuration across VM sets in Azure. Azure is flexible that it provides the option to make advantage of Puppet Enterprise.  Windows azure offers Puppet Enterprise in Marketplace so that you can easily spin a VM for Puppet Enterprise.

Go to Azure portal and click New and type ‘puppet enterprise’ as the search entry


Select the template and proceed to provide Puppet Master VM details such as Master VM name, console password, user name, SSH key etc.

Once the VM is created, you can get the public address DNS name label of the VM from the portal.

Using an SSH client, run the command ssh @ with the DNS name you found above (fully qualified domain name -FQDN). You will be asked to accept the remote host’s public key. Accept and provide the VM authentication password.

Once the VM is provisioned, you can access Puppet Enterprise Console using https:// .  In the authentication dialog, use ‘admin’ as user name and provide the console password that you entered while configuring puppet master.  This completes the first stage and next will be to install and configure puppet agent.

1- Create a windows server VM to install puppet agent

  • Click New, go to Marketplace and select ‘Virtual Machines’
  • Select Windows Server and image version (e.g. Windows server 2012 R2 Datacenter)
  • Click ‘create’ and provide user name, password, select pricing tier, resource group, location settings etc.
  • Click ‘create’ to provision the VM

2- Install Puppet Agent

  • Navigate to the blade of your VM
  • Go to ‘Configure’ and click ‘Extensions’
  • Click ‘Add’ in the Extensions box and click ‘Puppet Ent Agent’ ribbon, and click create
  • On the add extension blade, supply the fully qualified domain name of the Puppet Master (created in previous step above)
  • Click ‘create’

Windows Azure – Automation of Configuration across VMs

What are the options or tools available if you want to maintain consistent state or configuration to all your VMs in Windows Azure?

The first approach is to use Custom Script Extension. Set-AzureVMCustomScriptExtension command can be used from Powershell to add the Custom Script extension to an existing virtual machine.

However this approach can become inefficient or difficult to manage in a scaled environment with large number or different groups of VMs. Automation Desired State Configuration (DSC) can be used in such scenarios to set and maintain consistent configurations and states across all your VMs. You configure them and DSC push these to all nodes.

DSC extends PowerShell with ‘Configuration’ syntax with which you can set all the required configuration details for nodes.

Configuration SampleDSCConfig 
 Node "MyNode1" 
 #Enable IIS
 WindowsFeature IIS 
 Ensure = "Present"
 Name = "Web-Server"

 #Install ASP.NET 4.5
 WindowsFeature ASP
 Ensure = “Present”
 Name = “Web-Asp-Net45”

DSC can be used to perform many practical tasks/configurations across VMs such as:

• Setting server roles and features
• Registry settings
• Files and directories
• Start/stop processes and services
• Manage user accounts
• Deploy software
• Run Windows PowerShell scripts
• Managing environment variables
• Fix configuration drifts

Given below is another example of setting a registry value:

Configuration SampleDSCConfig 
Node "MyNode1" 
 Registry DisableShutdownTracking
 Ensure = "Present"
 ValueName = "MyValueName"
 ValueData = "0"
 ValueType = "Dword"
 Force = $true

For advanced configuration and management of your scaled VM infrastructure, you can also use CM tools such as Puppet and Chef which will be described in another blog.

ApplicationInsights.config – Tailoring Application Insights Configuration

We have seen the use of Application Insights configuration file in my previous article that described how to integrate AI to your application. Today, we will explore the sections of ApplicationInsights.config (Note that the file is ApplicationInsights.xml for Java web apps) in detail.

As mentioned in that article, this file get automatically added to your application when you add the ApplicationInsights to your application via NuGet or if you specify the AI integration while creating a new project in Visual Studio. And the file will have the default entries/configuration values as shown below:


I have described the key sections in this configuration file  below:

Telemetry Modules

As shown above, each module added in this section collects the specific data/counts. You can add or remove line items for these module nodes depending on the information that you want to collect. Some of the common tracker modules under this section are:

Dependency Tracking

You might have noticed this telemetry data in the graphs that I posted in my previous articles which talked about creation of AI telemetry charts. This data represents the number of calls that your application makes to the external databases or services.

<Add Type=”Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector” />

Performance collector

This is to collect system performance parameters such as your CPU and memory load.

<Add Type=”Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector”>

Application Insights Diagnostics

Use this if you want to collect error information from the AI instrumentation.

<Add Type=”Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights” />

Developer Mode

Use this if you want your application to send telemetry data one at a time while you step through your lines of code while debugging. Yes, you do not need this in your production configuration.

<Add Type=”Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer” />

Web Request Tracking

Used to collect the http requests, response time and response codes

<Add Type=”Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web” />

Exception tracking

This one collects data for unhandled exceptions in your applications. Very useful indeed!

<Add Type=”Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web” />


Telemetry Channel

This is responsible for buffering and sending the telemetry data collected in your application.

 Telemetry Initializers


Notice the screenshot above and the initializers placed for client IP, Session, User, Domain, Device etc. These are set to set the context properties along with the telemetry data that is collected and sent to the AI service.

Instrumentation Key


Use this section to specify the instrumentation key of the desired Application Insights Resource that you set up in your Azure account. Refer my previous article here for learning more about creating AI resource in Azure.


Adding Custom Application Insights instrumentaiton to Web Pages

In my previous article, we explored how to configure Application Insights to your application. The configuration explained there applies to the entire application which is good. The immediate doubt for many would be – Is it possible to track specific pages or custom events in specific pages in my applicaion using Application Insights?  The answer is Yes.

If you are familiar using Google Analytics (note that the objectives for Azure AI and Google Analytics aren’t the same; hence no comparison intended here), it is similar method that we have to add custom instrumentation to your pages using Application Insight.

Before we start, here are the prerequisites

  • Windows Azure Account
  • An Application Insights resournce created in Azure (explained here)
  • A running web application (Azure or on-premise hosted)

Login to your Azure account and select the Application Insights resource that you want to use for instrumentaiton.


You will be provided with the code snippet below.

   var appInsights=window.appInsights||function(config){     function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t     }({         instrumentationKey:"**********************************"     });             window.appInsights=appInsights;     appInsights.trackPageView();

To start with, copy this code and insert to HTML code of the web page that you want to track. Upload/redeploy your application and load the page few times to collect instrumentation data.

To view the metrics, go to Azure portal. Select the Application Insights resource. Use the “Add tiles” option  and drag the “Usage Timeline” and “Overview Timeline” charts from the default list



You can see the page views, sessions and users statistics.


Let us analyze this further. By default, you have an entry which tracks the page views.



If you want to track a custom event in your client page, you can use

(Javascript Syntax)


where the entry “MyEvent” stands for the custom event which can be tracked in the AI resource.

How to view and analyze custom events

As we did in the previous step, you can add default chart for “Custom Event” using the Add Tiles option or you can search for the event and add a custom chart.



So this will get you started. Some of the common APIs are listed below.

  • TrackPageView
  • TrackEvent
  • TrackMetric
  • TrackException
  • TrackRequest
  • TrackTrace
  • TrackDependency

There are various options to add custom tracking based on whether you are working on server side or client side code. The code syntax for doing the same in other languages are :


var tc = new TelemetryClient();


TelemetryClient tc = new TelemetryClient();


var AppInsights = require('applicationinsights');
var appInsights = new AppInsights({instrumentationKey: "<my instrumentation key>"});
appInsights.trackEvent("My event", { custom: "properties" });