Using New Relic to Monitor Applications on AWS OpsWorks

A good practice for maintaining highly available applications is to monitor the metrics that impact performance and service levels. AWS OpsWorks includes built-in integration with 14 Amazon CloudWatch metrics, including load, CPU, and memory, but you may also want to monitor other metrics, such as disk-space utilization or application-level metrics such as error rates.

That’s where monitoring solutions from New Relic can help. In addition to server-level metrics, New Relic offers application metrics that give deeper visibility into how your AWS OpsWorks application is running.

This blog post explains how to use community Chef cookbooks to enable New Relic monitoring on your application’s instances using the OpsWorks PHP walk-through as an example.

1. Create a cookbook repository

Before starting the walk-through, first create a repository that references the community cookbook using a Berksfile, for example on GitHub:

OpsWorks 1

The Berksfile needs two lines to reference the community cookbook:

source ""
cookbook "newrelic"

And that’s it; no other files are necessary in the cookbook repository.

You might be curious about the recipes we are going to use from the New Relic cookbook. This blog uses two recipes:

  1. newrelic::default installs the New Relic agent that performs the server monitoring
  2. newrelic::php-agent configures the agent to monitor the PHP application

2. Create a stack

Now you’re ready to create an OpsWorks stack using the OpsWorks console:

  1. Select Add a Stack to create an OpsWorks stack.
  2. Give it a name and select Advanced.
  3. Set Use custom Chef Cookbooks to Yes.
  4. Set Repository type to Git.
  5. Set the Repository URL to the repository created in the previous step.
  6. Set Manage Berkshelf to Yes.
  7. In the Custom JSON box, add your New Relic license and some options that override the default values in the community recipe. (You can get a free trial license when you sign up for New Relic.)
    "newrelic": {
        "license": "---ADD-YOUR-NEWRELIC-LICENSE-HERE---",
        "php-agent": {
            "php_recipe": "mod_php5_apache2::default",
            "config_file": "/etc/php.d/newrelic.ini"

8. Click the Add Stack button at the bottom of the page to create the stack.

OpsWorks 2

3. Create and configure a Layer

Now that the stack is set up, you need to create a layer. For this example we will use the PHP layer:

  1. Select Add Layer.
  2. Choose the PHP App Server layer. Click Add Layer.
  3. Click the layer’s edit Recipes action and scroll to the Custom Chef recipes section. You will notice there are several headings—Setup, Configure, Deploy, Undeploy, and Shutdown—that correspond to OpsWorks lifecycle events. OpsWorks triggers these events at these key points in the instance’s lifecycle, which runs the associated recipes.
  4. Enter newrelic::default, newrelic::php-agent next to Setup, click + to add it to the list and click the Save button at the bottom to save the updated configuration. OpsWorks will then run this recipe whenever you initially boot an instance in this layer.

OpsWorks 3

4. Launch Instances

After you’ve saved your layer, add some instances and start them.

OpsWorks 4

5. Create and deploy an app

Once you’ve started your instances:

  1. In the navigation pane, click Apps and on the Apps page, click Add an app.
  2. On the App page, give it a Name.
  3. Choose the app’s repository type. The example app is stored in a Git repository.
  4. The app’s repository URL. The example URL is: git://
  5. The app’s branch or version. This part of the walkthrough uses the version1 branch.
  6. Keep the default values for the remaining settings and click Add App.
  7. To install the code on the server, you must deploy the app. It will take some time for your instances to boot up completely. Once they show up as “online” in the Instances view, navigate to Apps and click deploy in the Actions column.
  8. Once the deployment is complete, you can see your app by deleting the public IP address of the server.

6. Check New Relic

Your servers should now be ready to view in the New Relic Servers view.

OpsWorks 5

When you navigate to the New Relic APM view, you can see the application metrics for the running app servers:

OpsWorks 6


This is a nice example of the combined power of OpsWorks, Berkshelf, community cookbooks, and New Relic. OpsWorks’ custom JSON allows you to provide your license code without having to put it in the recipe and expose your license key in a repository.

Finally, note that this example did not specify a version in the Berksfile. Before using something like this on production servers, you may want to modify it to include a specific version. That way, if the New Relic cookbook is updated, and a newer version is not compatible, your servers will still use the one that worked before. You can read more about versions and Berkshelf in general at

Author bio: Guest author Chris Barclay is a senior product manager at Amazon Web Services.

This post was written by a guest contributor. Please see their biographical details at the top of the post above. View posts by .

Interested in writing for New Relic Blog? Send us a pitch!