Last Updated: February 25, 2016
·
2.833K
· traviscannon

Add New Relic To Elastic Beanstalk for .NET

Add New Relic To Elastic Beanstalk for .NET

The instructions and files in this post can be used to configure an EC2 instance to install both the New Relic .NET Agent and Server Monitor on an EC2 deployed inside of an Elastic Beanstalk, without creating a custom AMI. Once configured, EC2s will begin reporting application and server metrics automatically to New Relic, even as the Elastic Beanstalk scales up and adds more EC2s.

Steps

  1. Create a top-level directory in your source bundle called .ebextensions and add newrelic.config to it.
  2. Change the values in newrelic.config to match your configuration, where: downloadpathto is the URL to download the PowerShell script and New Relic Agents (e.g. an S3 bucket), platform is the installer appropriate for your system (i.e. x86 or x64), version is the latest version of the New Relic Agent, and newreliclicense_key is your New Relic license key.
  3. Add an application setting to your application's configuration (i.e. web.config) named NewRelic.AppName, and set its value to the name of the application.
  4. Deploy your application to Elastic Beanstalk.

Code

newrelic.config

files:
  "C:\\Users\\Public\\Downloads\\EnableEc2SetComputerName.ps1":
    source: http://<download_path_to>/EnableEc2SetComputerName.ps1
  "C:\\Users\\Public\\Downloads\\NewRelicAgent.msi": 
    source: http://<download_path_to>/NewRelicAgent_<platform>_<version>.msi
  "C:\\Users\\Public\\Downloads\\NewRelicServerMonitor.msi": 
    source: http://<download_path_to>/NewRelicServerMonitor_<platform>_<version>.msi
commands:
  ec2setcomputername-enable:
    command: powershell.exe -ExecutionPolicy Bypass -File "C:\\Users\\Public\\Downloads\\EnableEc2SetComputerName.ps1"
  install_newrelic_agent:
    command: msiexec.exe /i "C:\\Users\\Public\\Downloads\\NewRelicAgent.msi" /qb NR_LICENSE_KEY=<new_relic_license_key> INSTALLLEVEL=50
  install_newrelic_servermonitor:
    command: msiexec.exe /i "C:\\Users\\Public\\Downloads\\NewRelicServerMonitor.msi" /L*v install.log /qn NR_LICENSE_KEY=<new_relic_license_key>
container_commands:
  reboot-instance:
    command: powershell.exe -Command "Restart-Computer"

web.config

<configuration>
  <appSettings>
    <add key="NewRelic.AppName" value="Your Application Name Here"/>
  </appSettings>
</configuration>

EnableEc2SetComputerName.ps1

$EC2SettingsFile="C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml"
$xml = [xml](get-content $EC2SettingsFile)
$xmlElement = $xml.get_DocumentElement()
$xmlElementToModify = $xmlElement.Plugins

foreach ($element in $xmlElementToModify.Plugin)
{
    if ($element.name -eq "Ec2SetComputerName")
    {
        $element.State="Enabled"
    }
}

$xml.Save($EC2SettingsFile)

Notes

  • The EnableEc2SetComputerName.ps1 PowerShell script configures the EC2 instance to use a unique computer name based off their private IP address. This allows each server to be reported independently of other EC2 instances sending data to New Relic. Without configuring unique names, EC2s will appear as a single server in NewRelic. This modification to the EC2 requires a reboot.

Reference

Source

1 Response
Add your response

Thanks for sharing

over 1 year ago ·