Blog

"Knowledge has no value unless you use it and share it"

How to deploy Application Insights Status Monitor Preview on a Cloud Service Webrole

Update

Finally, we have a sample repository available. This shows how to completely automate Status Monitor installation as part of the deployment pipeline. In addition, the repo has some other useful tips on setting up Application Insights. It does this using a trivial MVC Web Application as its baseline.

Original Post

What is a Status Monitor?

A Status Monitor is a component of the new Microsoft Application Insights Preview. It is intended to be installed on a Windows server hosting web applications through IIS. Once installed it will provide information about application dependencies. These include such as SQL queries and calls to 3rd party services.

Microsoft provided documentation and scripts for the Visual Studio Online version of Application Insights. Unfortunately, this SDK is now deprecated. Similar scripts for the new version are not yet available.

How Does the Status Monitor Work?

We did a little digging into the Status Monitor pipeline. It turned out that it was using ETW. There is no background service running. Instead, the components are plugged directly into IIS. If you installed Status Monitor and included the Application Insights SDK into your application before building and deploying, you are pretty much ready to go. All that is left is to reset the IIS pipeline to let the necessary components load.

Because we want to be able to deploy easily to Cloud Service Web roles, we can leverage the existing process. As a result, we can replace the PowerShell script with a new one.

if(${env:InstalledStatusMonitor} -eq 1)
{
    Write-Host "Status monitor has already been installed on this machine by this script" -ForegroundColor Green
}

Write-Host "Using chocolatey to install the Web Platform Installer ..."  -ForegroundColor Green
iex ((new-object net.webclient).downloadstring('https://chocolatey.org/install.ps1'))
cinst webpi -y
Stop-Process -Name WebPlatformInstaller

Write-Host "Using Web Platform Installer to install Status Monitor ..." -ForegroundColor Green
&"$env:ProgramFiles\Microsoft\Web Platform Installer\WebpiCmd.exe" /Install /AcceptEula /Products:ApplicationInsightsStatusMonitor

Write-Host "Adding app pool account to the 'Performance Monitor Users' local group" -ForegroundColor Green
$group = "Performance Monitor Users"
$user = "Network Service"
$computer = $(Get-WmiObject Win32_Computersystem).name
$de = [ADSI]"WinNT://$computer/$group,group"
$de.psbase.Invoke("Add",([ADSI]"WinNT://$user").path)
Write-Host "Waiting 30 seconds for Status Monitor to finish its install ..." -ForegroundColor Green
Start-Sleep -Seconds 30

Write-Host "Stop-Starting services to enable tracing..." -ForegroundColor Green
# For some reason, even though Status Monitor calls "iisreset.exe /restart"
# calling it here leaves IIS and website stopped.
&iisreset.exe /restart

Write-Host "waiting a few seconds..." -ForegroundColor Yellow
Start-Sleep -Seconds 2
Write-Host "starting..." -ForegroundColor Yellow

Start-Service -Name W3SVC
Get-WebApplication | Select ApplicationPool -Unique | %{ Start-WebAppPool $_.applicationPool }
Get-Website | Start-Website
Write-Host "started" -ForegroundColor Yellow

Write-Host "Cleaning up running applications" -ForegroundColor Green
Stop-Process -Name Microsoft.Diagnostics.Agent.StatusMonitor

Write-Host "Setting environment variable to indicate status monitor has been installed" -ForegroundColor Green
[Environment]::SetEnvironmentVariable("InstalledStatusMonitor", "1", "Machine")

Write-Host "Installation complete" -ForegroundColor Green

In Finishing

At Greenfinch Technology we like to keep our clients up to date with the latest technologies and processes. If you have a project you would like a professional company to have a look at for you why not use our contact form.

Alternatively, you can give us a call at

+353 (0)1 818 2949

 

status Monitor

VIEW ALL BLOGS