Skip to content

Instantly share code, notes, and snippets.

  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save TravisCannon/6023875 to your computer and use it in GitHub Desktop.
How to add New Relic to an AWS Elastic Beanstalk EC2 for .NET without creating a custom AMI.

Add New Relic To Elastic Beanstalk for .NET

The instructions and files in this Gist 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:
    • download_path_to = URL to download the PowerShell script and New Relic Agents (e.g. an S3 bucket)
    • platform = choose the installer appropriate for your system (i.e. x86 or x64)
    • version = the latest version of the New Relic Agent
    • new_relic_license_key = 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.

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

$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)
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"
<configuration>
<appSettings>
<add key="NewRelic.AppName" value="Your Application Name Here"/>
</appSettings>
</configuration>
@robbileifss
Copy link

Hi,
How can I have this not execute on my dev but only on my prod beanstalk ? I am publishing thru my visual studio btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment