3

I pulled this from the New Relic docs. I'm looking for a way to replace YourNewRelicLicense and NameOfYourServer with environment variables set up on the ec2 instance.

packages: 
  yum: 
    newrelic-sysmond: [] 
  rpm: 
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm 
commands: 
  "01": 
    command: nrsysmond-config --set license_key=YourNewRelicLicense 
  "02": 
    command: echo hostname=NameOfYourServer >> /etc/newrelic/nrsysmond.cfg 
  "03": 
    command: /etc/init.d/newrelic-sysmond start

Is this possible?

ThomasReggi
  • 621
  • 2
  • 10
  • 25

2 Answers2

2

I had the same issue. With a little testing I came up with an updated version of what New Relic provides that allows use of environment variables from the application config in elastic beanstalk.

Final version looked like this

packages:
  yum:
    newrelic-sysmond: []
  rpm:
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
container_commands:
  "01":
    command: /usr/sbin/nrsysmond-config --set license_key=${APP_NR_LIC}
  "02":
    command: echo hostname=$HOSTNAME >> /etc/newrelic/nrsysmond.cfg
  "03":
    command: /etc/init.d/newrelic-sysmond start

Just replace APP_NR_LIC with whatever variable you use to set you license key. This is working reliably for me.

Thanks to Maciej for his research here.

Hobbit
  • 21
  • 5
  • I have an alternative way of doing this without `container_commands` below. Although I'm not sure what the difference is. – ThomasReggi Apr 18 '16 at 02:38
  • 1
    The difference between `commands` and `container_commands` is when they execute. `commands` execute before the application and web server are set up, while `container_commands` are executed after application and web server are set up but before the application version is deployed. `container_commands` have access to your environment variables where `commands` do not. – Hobbit Jun 01 '16 at 08:01
0

Here's an example script that works, and will get environment variables and works with commands as opposed to container_commands.

packages:
  yum:
    newrelic-sysmond: []
  rpm:
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
files:
  "/root/env.js":
    mode: "00755"
    owner: root
    group: root
    encoding: plain
    content: |
      #!/usr/bin/env node
      var strings = []
      process.stdin.resume()
      process.stdin.setEncoding('utf8')
      process.stdin.on('data', function(data) {
        var json = JSON.parse(data)
        for (var key in json) {
          var val = json[key]
          strings.push(key + '="' + val + '"')
        }
      })
      process.stdin.on('end', function() {
        var output = strings.join('\n')
        process.stdout.write(output)
      })
commands:
  "05":
    command: ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node
  "08":
    command: sudo /etc/init.d/newrelic-sysmond stop
  "09":
    command: sudo /opt/elasticbeanstalk/bin/get-config environment | sudo /root/env.js > file
  "10":
    command: source ./file && sudo nrsysmond-config --set ssl=true license_key=$NEW_RELIC_LICENSE_KEY
  "12":
    command: sudo /etc/init.d/newrelic-sysmond start
ThomasReggi
  • 621
  • 2
  • 10
  • 25