Convox Community

Installing Newrelic Infrastructure Agent

We would like to install the Newrelic Infrastructure agent on our EC2 instances to collect infrastructure metrics-- I’ve seen some docs for Datadog suggesting deploying as a service, but wondered at the best practice for deploying. Is it just deployed as a service in a container?

Thanks!

Hello,

This can be achieved by setting the InstanceRunCommand to execute a script that will setup the agent when the EC2 instance boots:

convox rack params set InstanceRunCommand="curl https://user:pass@some-private-server/instance-run-command.sh | sh"

The instance-run-command.sh script being as follows:

#!/bin/bash -ex

echo "license_key: KEY" | tee -a /etc/newrelic-infra.yml
curl -o /etc/yum.repos.d/newrelic-infra.repo \
  https://download.newrelic.com/infrastructure_agent/linux/yum/el/6/x86_64/newrelic-infra.repo
yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'
yum install newrelic-infra -y

You could also pass the whole thing as the value for the InstanceRunCommand param, but it’s easier to manage as a separate script. If you assign an InstancePolicy in the rack params, you could also probably fetch it from S3 without the need to authenticate.

Rather than installing it on every instance boot and potentially introducing a point of failure I did this by building a custom AMI with hashicrp packer - the AMI IDs are in rack source code - I believe they are just the ECS optimized AMIs from AWS. However, to keep the AMI up-to-date, you do have do do a couple of manual steps each time.

For packer, the provisioner is just shell, with the lines in the shell script above as provided by NewRelic. Once the AMI is built, Ami is a convox rack param available to update to override the default one.