I'm configuring nrsysmond to run on an Elastic Beanstalk container that hosts Generic Docker containers.
Is there any way to get the instance index so that I could combine that with a constant? Something like Production-1, Production-2, etc.
The configuration I'm using looks like this:
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=`/opt/elasticbeanstalk/bin/get-config environment | jq .NEW_RELIC_LICENSE_KEY | sed -e 's/"//g'`
"02":
command: echo hostname=`/opt/elasticbeanstalk/bin/get-config environment | jq .RAILS_ENV | sed -e 's/"//g'` >> /etc/newrelic/nrsysmond.cfg
"03":
command: usermod -a -G docker newrelic
"04":
command: /etc/init.d/newrelic-sysmond restart
This works great, but sets all the hostnames to the same thing. I don't want to use the Elastic Beanstalk hostname, as those change every time the instances scale. This clogs up New Relic with dead instances.
This is on 64bit Amazon Linux 2015.03 v1.4.3 running Docker 1.6.2
I've found a solid way of determining the current Elastic Beanstalk index instance.
"02":
command: echo `ec2-describe-tags --filter key=Name | grep \`curl -sq http://169.254.169.254/latest/meta-data/instance-id\`` | awk '{print $5}' >> /etc/newrelic/environment-name
"03":
command: aws elasticbeanstalk describe-environment-resources --environment-name `cat /etc/newrelic/environment-name` --region us-east-1 | jq '.EnvironmentResources.Instances' | ruby -e "require 'json'; puts JSON.parse(ARGF.read).find_index({'Id' => '$(curl -sq http://169.254.169.254/latest/meta-data/instance-id)'})" >> /etc/newrelic/instance-index
"04":
command: echo hostname=`/opt/elasticbeanstalk/bin/get-config environment | jq .RAILS_ENV | sed -e 's/"//g'``cat /etc/newrelic/instance-index` >> /etc/newrelic/nrsysmond.cfg
The idea is:
I hope this helps anyone else trying to deal with figuring out which Elastic Beanstalk instance you're on.