Measuring Application Performance with NewRelic
You want to make sure you application runs well and delivers a great experience for you users. One of the best choices for monitoring an application running on Heroku is NewRelic.
Introduction
To get that data to NewRelic you:
- Install the add-on
- Download and install their monitor package into your application
- Setup your unique account key
- Re-deploy your application
Install the Addon
NewRelic has several plan types depending on your needs, but we’ll use the free Stark plan. From your project directory:
Terminal
$
|
|
Then, as it suggests, you can open the Dev Center documentation about NewRelic:
Terminal
$
|
|
Install the Monitor
NewRelic offers monitor packages for Java, Ruby, Python, Node.js, and Clojure.
Detailed instructions to install the agent can be found in the Dev Center. We’ve already included the agent in the sample application, which involved:
- Downloading the latest Java agent version from http://download.newrelic.com/newrelic/java-agent/newrelic-agent/
- Extracting it into the project directory
Load the Monitor
For Java applications we can load the monitor when the application starts by modifying the JAVA_OPTS
environment variable.
Remember that you can list out your existing environment variables with heroku config
:
Terminal
$ |
|
We need to add -javaagent:newrelic/newrelic.jar
to the end of JAVA_OPTS like this:
Terminal
$ |
|
Now when our dyno restarts it’ll load the monitor.
Restarting Manually
If you had added the monitor yourself, you’d want to commit to Git and push to Heroku.
But since the files were already in place for the sample app, we can just force a restart to pickup the new environment variables:
Terminal
$
|
|
Generate Data
Run heroku open
to open your production application in your browser. Click around through a few different screens to generate a bit of data.
View Results in NewRelic
You can view NewRelic from within your Heroku dashboard:
- Visit https://dashboard.heroku.com/apps
- Click your application
- Under the Add-ons heading, click
New Relic
- You’ll be taken to the NewRelic interface and automatically logged in
There you should see the data from the last few minutes of your production activity.
In the future, you could also run the following from your command line: heroku addons:open newrelic
What You’ve Learned
- Heroku’s add-on system makes it easy to install third-party tools like NewRelic
- NewRelic can be used to monitor the health of your application