Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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>

r0n22 commented Sep 25, 2013

I am trying to use this system.

I am getting New Relic installed but the actual application does not deploy.

I am getting in the event log:

  • Failed to deploy application.
  • Some instances have not responded to commands. Responses were not received from [XXXXXXX]

I am very new with AWS and Beanstalk.

Could you shed any light on how to fix this?

tucaz commented Oct 26, 2013

@r0n22 take a look at the logs. In my case that happened due to lack of permissions to access the s3 bucket where the installers were. I made them public and that did the job. It's working.

will this reinstall the newrelic agents and reboot the servers every time i redeploy the application ?

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