Elastic Beanstalk 上 New Relic 的 nrsysmond 的唯一主机名

Unique Hostname for New Relic's nrsysmond on Elastic Beanstalk

我在托管通用 Docker 容器的 Elastic Beanstalk 容器上将 nrsysmond 配置为 运行。

有什么方法可以获取实例索引,以便我可以将其与常量结合起来吗?诸如 Production-1、Production-2 等

我使用的配置如下所示:

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

这很好用,但将所有主机名设置为同一名称。我不想使用 Elastic Beanstalk 主机名,因为每次实例扩展时主机名都会更改。这会用死实例堵塞 New Relic。

这是在 64 位亚马逊 Linux 2015.03 v1.4.3 运行ning Docker 1.6.2

我找到了确定当前 Elastic Beanstalk 索引实例的可靠方法。

"02":
  command: echo `ec2-describe-tags --filter key=Name | grep \`curl -sq http://169.254.169.254/latest/meta-data/instance-id\`` | awk '{print }' >> /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 

想法是:

  • 获取 Elastic Beanstalk 环境名称
  • 获取该环境的实例列表
  • 在该索引中查找当前实例
  • 将 New Relic 主机名设置为 RAILS_ENV-index

我希望这可以帮助其他任何人尝试处理您正在使用的 Elastic Beanstalk 实例。