New Relic’s Community Forum is designed to be a place for our users to share their experiences, questions, problems, and fixes. The collective expertise and creativity of the New Relic community has generated some outstanding solutions to everyday issues, and we want to call out some of them in the area of .NET agent deployment excellence.

Basic installation

Installing New Relic’s .NET agent is designed to be simple: run the installer on the target host and choose the features you want to include. For Microsoft Azure deployments, install one of our NuGet packages. Installation requires a reset of IIS for the software to load into your application. To upgrade, we recommend first stopping IIS, installing the newer agent version, and then starting up IIS again.

It’s also possible to perform a “silent” (manual) install using msiexec.exe, for example:

msiexec.exe /i C:\NewRelicAgent.msi /qb NR_LICENSE_KEY=<license key> INSTALLLEVEL=1

See the documentation for complete manual installation options.

Leveraging PowerShell

Scripting the silent installation provides convenience and flexibility. Here’s an example script provided by community member Jon Carl in this post:

$msiName = <name of your msi>
$licenseKey = <your NR license key>
$arguments = "/i $msiName /L*v install.log /qn NR_LICENSE_KEY=$licenseKey"

if ($msiName -ne $null) {
    $exitCode = (Start-Process -FilePath "msiexec" -ArgumentList $arguments -Wait 
-PassThru).ExitCode;
    if($exitCode -eq 0) {
        Write-Host "Installation successful!" -ForegroundColor Green
    } else {
        Write-Host "Installation unsuccessful. Exitcode: $exitCode" -ForegroundColor Red
    }
}

This script works great when run directly on the target machine. Another forum user (Kym McGain) noticed that the installation didn’t complete before the session ended when executing the script remotely. This caused the installer to quit partway through. Kym posted this script that uses a ‘while’ loop to ensure the installer completes. As a bonus, it stops IIS before and restarts it after the software installs. As mentioned above, these steps are usually needed when upgrading.

$installNewRelic = {
    $runProcess = {
        param($process,$arguments)

        $res = Start-Process -FilePath $process -ArgumentList $arguments -Wait -PassThru

        while ($res.HasExited -eq $false) {
            Write-Host "Waiting for $process..."
            Start-Sleep -s 1
        }

        $exitCode = $res.ExitCode
        if($exitCode -eq 0) {
            Write-Host "$process successful!" -ForegroundColor Green
        } else {
            Write-Host "$process unsuccessful. Exitcode: $exitCode" -ForegroundColor Red
        }
    }

    $msiName = <name of your msi>
    $licenseKey = <your NR license key>

    $arguments = "/i $msiName /L*v install.log /qn NR_LICENSE_KEY=$licenseKey"

    Invoke-Command $runProcess -ArgumentList "IISRESET","/STOP"
    Invoke-Command $runProcess -ArgumentList "msiexec.exe",$arguments
    Invoke-Command $runProcess -ArgumentList "IISRESET","/START"
}

Chef, Puppet, and Chocolatey

Deployment options abound for modern Web developers. These solutions often require a known download path and installer name. New Relic offers a consistent filepath and MSI name for the agent in an effort to make automated deployment easier for .NET customers:

http://download.newrelic.com/dot_net_agent/release/NewRelicDotNetAgent_x64.msi
http://download.newrelic.com/dot_net_agent/release/NewRelicDotNetAgent_x86.msi

Several Community members have created packages for these utilities. Chocolatey users are invited to use the following NuGet package created by kireevco:

https://chocolatey.org/packages/newrelic-dotnet

New Relic community member ePitty built a Puppet module to handle .NET agent deployment:

https://github.com/epitty1023/puppet-newrelicappmon

Chef users, meanwhile, can check out the following cookbook for .NET and many other platforms New Relic supports:

http://community.opscode.com/cookbooks/newrelic

New Relic Community member E_Bow wrote a Chef recipe that goes a step further by stopping IIS before the installation and starting it again after completion:

#Stop IIS
iis_site 'Website' do
  action [:stop]
end

# install latest Newrelic agent from web
include_recipe 'newrelic::repository'
include_recipe node['newrelic']['dotnet-agent']['dotnet_recipe']

license = node['newrelic']['application_monitoring']['license']

windows_package 'Install New Relic .NET Agent' do
  source node['newrelic']['dotnet-agent']['https_download']
  options "/qb NR_LICENSE_KEY=#{license} INSTALLLEVEL=#{node['newrelic']['dotnet-agent']['install_level']}"
  installer_type :msi
  action :install

end

#Start IIS
iis_site 'Website' do
  action [:start]
end

The author states that they were unable to pull the New Relic license key from the configuration JSON in Chef Overrides, requiring them to modify the config file on each machine and manually enter the key. We invite any Chef experts out there to extend and improve this recipe so that it correctly pulls the license key.

We are continually impressed by the smarts and spirit of our New Relic Community Forum members, and jump at the chance to highlight their contributions. Look for more Forum projects in the New Relic blog in the future.

Do you have your own approach, tips, or recipes? Please share them in the New Relic Community Forum.

 

Background image courtesy of Shutterstock.com.

Wyatt Lindsey is a team lead for New Relic Support Engineering. He enjoys working with various Web technologies, particularly those involving Node and AngularJS. He’s passionate about helping customers get the most out of New Relic. View posts by .

Interested in writing for New Relic Blog? Send us a pitch!