AWS DevOps & Developer Productivity Blog
Using New Relic to monitor applications on AWS OpsWorks
1. Create a cookbook repository

source “https://api.berkshelf.com”
cookbook “newrelic”, git: ‘git://github.com/escapestudios-cookbooks/newrelic.git’, tag: ‘1.0.6’
|
-
newrelic::default installs the New Relic agent that performs the server monitoring
-
newrelic::php-agent configures the agent to monitor the PHP application
2. Create a stack
- Select Add a Stack to create an OpsWorks stack.
- Give it a name and select Advanced.
- Set Use custom Chef Cookbooks to Yes.
- Set Repository type to Git.
- Set the Repository URL to the repository created in the previous step
- Set Manage Berkshelf to Yes.
- In the Custom JSON box, add your New Relic license code 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”}}}
- Click the Add Stack button at the bottom of the page to create the stack.

3. Create and configure a Layer
- Select Add Layer.
- Choose the PHP App Server layer. Click Add Layer.
- 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.
- 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 the recipes whenever you initially boot an instance in this layer.

4. Launch Instances

5. Create and deploy an app.
- In the navigation pane, click Apps and on the Apps page, click Add an app.
- On the App page, give it a Name.
- Enter the app’s repository type. The example app is stored in a Git repository.
- Enter the app’s repository URL. The example app’s repository URL is: git://github.com/amazonwebservices/opsworks-demo-php-simple-app.git
- Enter the app’s branch or version. This part of the walkthrough uses the version1 branch.
- Keep the default values for the remaining settings and click Add App.
- 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.
- Once the deployment is complete, you can see your app by selecting the public IP address of the server.
6. Check NewRelic


Conclusion: