Skip to content

Instantly share code, notes, and snippets.

@MrCoffey
Created January 27, 2017 20:04
Show Gist options
  • Save MrCoffey/702c6f4dd9852df7f182b9dfc2793944 to your computer and use it in GitHub Desktop.
Save MrCoffey/702c6f4dd9852df7f182b9dfc2793944 to your computer and use it in GitHub Desktop.
Newrelic configuration for elasticbeanstalk
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/01-get-env-name.py":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env python
# https://steelpangolin.wordpress.com/2015/01/30/how-to-find-the-name-of-an-elastic-beanstalk-environment-from-inside-one-of-its-instances/
import boto.utils
import boto.ec2
iid_doc = boto.utils.get_instance_identity()['document']
region = iid_doc['region']
instance_id = iid_doc['instanceId']
ec2 = boto.ec2.connect_to_region(region)
instance = ec2.get_only_instances(instance_ids=[instance_id])[0]
env = instance.tags['elasticbeanstalk:environment-name']
print(env)
packages:
yum:
newrelic-sysmond: []
rpm:
newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
commands:
100-setup-license-key:
command: nrsysmond-config --set license_key=YOUR_LICENSE_KEY
200-write-hostname:
command: echo hostname=`python /opt/elasticbeanstalk/hooks/appdeploy/pre/01-get-env-name.py` >> /etc/newrelic/nrsysmond.cfg
300-init-newrelic:
command: /etc/init.d/newrelic-sysmond start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment