Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
211 lines (141 sloc) 8.28 KB
---
title: New Relic
owner: Partners
---
<strong><%= modified_date %></strong>
## <a id='managing'></a>Managing Services ##
To create and bind a service instance from the command line, see [Managing Service Instances with the CLI](/devguide/services/managing-services.html).
### <a id='create'></a>Creating a Service Instance ###
An instance of this service can be provisioned via the CLI with the following
command:
<pre class="terminal">
$ cf create-service newrelic standard INSTANCE
</pre>
Replace `INSTANCE` with a name that is meaningful to you.
### <a id='bind'></a>Binding Your Service Instance ###
Bind the service instance to your app with the following command:
<pre class="terminal">
$ cf bind-service APP INSTANCE
</pre>
Replace `APP` with the app that you are binding and `INSTANCE` with the name
that you gave your service instance.
### <a id='sso'></a>Single Sign On ###
Follow the steps below to log into your New Relic Account via SSO:
1. Log into the [Apps Manager](http://console.run.pivotal.io).
1. Find your New Relic service instance on the **Space** page in which you
created it.
1. Click **Manage** to log into the New Relic account for your instance via SSO.
## <a id='notes'></a>Important Notes ##
* To opt out of marketing emails from New Relic, log into the New Relic dashboard via SSO as described above and click the account drop-down in the top-right. In User Preferences, de-select **I want to receive information emails**, then click **Save email preferences**.
* On the User Preferences page of the New Relic site is a field to change the email address for the account. <strong>Do not change the information in this field</strong>. Changing this information breaks SSO integration and prevents you from logging in to your account.
## <a id='sample-app'></a>Sample Applications ##
### <a id='sample-java'></a>Java ###
[This sample Java app](https://github.com/cloudfoundry-samples/spring-music/tree/newrelic) takes advantage of the Java buildpack's zero-touch New Relic support. Create a NewRelic service instance on your Apps Manager dashboard. Use the included `manifest.yml` to indicate which services you want bound to your application. All you need to do is clone, create the service instance, build, and push!
<pre class="terminal">
$ git clone -b newrelic https://github.com/cloudfoundry-samples/spring-music.git
$ cd spring-music
$ ./gradlew assemble
$ cf push
</pre>
## <a id='using'></a>Using New Relic with your Application ##
In order for metrics for your application to be reported to New Relic, the following three requirements must be satisfied:
* A New Relic agent bundled with your application
* A configuration file the agent requires
* An account-specific license key configured in the configuration file
All three of these things can be found by logging into your New Relic account as described above, but we want to make it even easier than that. See our language-specific solutions below.
### <a id='ruby'></a>Ruby / Rails ###
1. Add the New Relic agent gem to your Gemfile.
~~~xml
gem 'newrelic_rpm'
~~~
Rebuild the bundle if you want to test locally, but this isn't required because Cloud Foundry will bundle the gem when you push your app.
<pre class="terminal">
$ bundle install
</pre>
1. Add a New Relic configuration file to your project. This file needs to be configured with your license key and application name, but we've modified New Relic's config file for Ruby to automatically read your application name and license key from environment variables which are set when the app is pushed. [Download our modified newrelic.yml here](./newrelic-ruby.yml) and save it to `config/newrelic.yml`.
<pre class="terminal">
$ wget -O config/newrelic.yml http://docs.run.pivotal.io/marketplace/services/newrelic/newrelic-ruby.yml
</pre>
1. All you have left to do is push your app! If you don't already have a New Relic service instance in your space, choose to create one when prompted. If you already have a New Relic service instance in your space, choose to bind to an existing service when prompted.
<pre class="terminal">
$ cf push
</pre>
1. Now generate some usage on your app and log into New Relic via SSO [as described above](#sso); you should see data coming through!
### <a id='java'></a>Java ###
1. Build your app.
1. Push your app to Cloud Foundry. If you don't already have a New Relic service instance in your space, choose to create one when prompted. If you already have a New Relic service instance in your space, choose to bind to an existing service when prompted.
<pre class="terminal">
$ cf push
</pre>
1. Now generate some usage on your app and log into New Relic via SSO [as described above](#sso); you should see data coming through!
<p class="note"><strong>Note</strong>: To specify the app name that New Relic uses, configure <code>JAVA_OPTS</code> with <code>-Dnewrelic.config.app_name=YOUR-APP-NAME</code>. Replace <code>YOUR-APP-NAME</code> with the desired app name.
</p>
### <a id='php'></a>PHP ###
1. Push the app:
<pre class="terminal">
$ cf push
</pre>
1. Create a New Relic service instance.
1. Bind the service instance to the app instance.
1. Re-stage the app:
<pre class="terminal">
$ cf restage app
</pre>
1. Go to the app URI and generate some usage data.
1. Go to console.run.pivotal.io, choose **Manage** under your New Relic service, and connect to your app data.
<p class="note"><strong>Note</strong>: To specify the application name which New Relic uses, add a <code>.user.ini</code> file to your app. For instance, to have your application
show in New Relic with two names, "Virtual Host 1" and "All Virtual
Hosts", you can set the following in <code>.user.ini</code>: <code>newrelic.appname="Virtual Host 1;All Virtual Hosts"</code>.</p>
## <a id='existing-license'></a>Using an Existing New Relic License Key
If you have an existing New Relic license key instead of one provided by the Services Marketplace, refer to the language-specific instructions below:
### <a id='license-ruby'></a>Ruby
1. Run the following command to set the `NEWRELIC_LICENSE` environment variable to your license key:
<pre class='terminal'>
cf set-env YOUR-APP-NAME NEWRELIC_LICENSE LICENSE-KEY
</pre>
1. Edit the `newrelic-ruby.yml` file obtained [earlier](#ruby) as shown below. The following change allows the `license_key` key to find your license key from the environment:
```
license_key: '<%= ENV["NEWRELIC_LICENSE"] %>'
```
### <a id='license-java'></a>Java
1. From the cf CLI run `cf cups` to create a user-provided New Relic service instance:
<pre class='terminal'>
cf cups newrelic_INSTANCE_NAME -p "{\"license_key\":\"LICENSE-KEY\"}"
</pre>
- Ensure that your New Relic instance name includes `newrelic`. This enables the New Relic Agent Framework to automatically configure the New Relic application to work with the service.
- You can also include a display name for the instance in the New Relic interface by including `\"app_name\":\"PCF-APP-NAME\"` in the JSON structure string.
- See [User-Provided Service Instances](../../../devguide/services/user-provided.html) for more information about the `cf cups` command.
1. Bind the service instance to any app that you want to use it.
1. Re-stage the app:
<pre class="terminal">
$ cf restage YOUR-APP
</pre>
### <a id='license-php'></a>PHP
Run the following command to set the `NEWRELIC_LICENSE` environment variable to your license key:
<pre class='terminal'>
cf set-env YOUR-APP-NAME NEWRELIC_LICENSE LICENSE-KEY
</pre>
## <a id='vcap-services'></a>VCAP_SERVICES ##
When you bind your New Relic service instance with your application, Cloud Foundry makes a request to New Relic for the license key for your account. When you restart your application, we write this key to the `VCAP_SERVICES` environment variable.
Format of `VCAP_SERVICES` environment variable:
~~~xml
{
"newrelic-n/a":[
{
"name":"newrelic-14e9d",
"label":"newrelic-n/a",
"plan":"standard",
"credentials":
{
"licenseKey":"EXAMPLEaaaaf813af7989fccb24a699cb22a4beb"
}
}
]
}
~~~
For more information, see [VCAP_SERVICES Environment Variable](/devguide/deploy-apps/environment-variable.html).
## <a id='support'></a>Support ##
[Contacting Service Providers for Support](../../contacting-service-providers-for-support.html)
* https://support.newrelic.com/
* support@newrelic.com
Documentation: https://newrelic.com/docs