Last active
July 29, 2016 16:08
-
-
Save sgtsquiggs/ba68cb064d3c35187708cf58f8fcca1b to your computer and use it in GitHub Desktop.
New Relic Server Monitoring on Elastic Beanstalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# installs and configures New Relic System Monitoring agent | |
# https://crondev.com/new-relic-server-monitoring-on-elastic-beanstalk/ | |
# requires `AmazonEC2ReadOnlyAccess` policy to get eb environment name | |
# | |
files: | |
"/opt/elasticbeanstalk/get-eb-env-name.py": | |
mode: "000755" | |
owner: root | |
group: root | |
content: | | |
#!/usr/bin/env python | |
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('%s-%s' % (env, instance_id.split('-')[-1])) | |
packages: | |
yum: | |
newrelic-sysmond: [] | |
rpm: | |
newrelic: https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm | |
commands: | |
1_configure_new_relic_hostname: | |
command: sed -i "s+#hostname=.*+hostname=`/opt/elasticbeanstalk/get-eb-env-name.py`+g" /etc/newrelic/nrsysmond.cfg | |
2_configure_cgroup_root: | |
command: sed -i "s+#cgroup_root=.*+cgroup_root=/cgroup+g" /etc/newrelic/nrsysmond.cfg | |
3_add_newrelic_to_docker_group: | |
command: usermod -a -G docker newrelic | |
container_commands: | |
1_configure_new_relic_key: | |
command: /usr/sbin/nrsysmond-config --set license_key=$NEW_RELIC_LICENSE_KEY | |
2_start_nrsysmond: | |
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
I've edited the
get-en-env-name
script to attach the significant part of the instance_id to the environment name, so that you see separate instances in newrelic.I've also added docker reporting support, and I've updated the newrelic agent to the latest x86_64 version.