Skip to content

Instantly share code, notes, and snippets.

@svenvarkel
Last active March 29, 2017 17:20
Show Gist options
  • Save svenvarkel/0cb7d53139eb0258640c65bd4542ef6b to your computer and use it in GitHub Desktop.
Save svenvarkel/0cb7d53139eb0258640c65bd4542ef6b to your computer and use it in GitHub Desktop.
Configure tag Name as hostname for New Relic
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/60_configure_newrelic_hostname.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
set -xe
export EC2_TAG_NAME=$(/opt/aws/bin/ec2-describe-tags --filter "resource-type=instance" --filter "resource-id=$(/opt/aws/bin/ec2-metadata -i | cut -d ' ' -f2)" --filter "key=Name" | cut -f5)
sed -i "s/#hostname=.*/hostname=$EC2_TAG_NAME/" /etc/newrelic/nrsysmond.cfg
/etc/init.d/newrelic-sysmond restart
exit 0
@svenvarkel
Copy link
Author

svenvarkel commented Mar 29, 2017

Added to .ebextensions/00_configure_newrelic_hostname.config file. The script will be executed upon app deployment and it would register EC2 tag "Name" as hostname at New Relic. By default it's a dynamic IP address and it's very hard to distinguish between different servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment