New Relic

Page last updated:

Managing Services

To create and bind a service instance from the command line, see Managing Service Instances with the CLI.

Creating a Service Instance

An instance of this service can be provisioned via the CLI with the following command:

$ cf create-service newrelic standard INSTANCE

Replace INSTANCE with a name that is meaningful to you.

Binding Your Service Instance

Bind the service instance to your app with the following command:

$ cf bind-service APP INSTANCE

Replace APP with the app that you are binding and INSTANCE with the name that you gave your service instance.

Single Sign On

Follow the steps below to log into your New Relic Account via SSO:

  1. Log into the Apps Manager.

  2. Find your New Relic service instance on the Space page in which you created it.

  3. Click Manage to log into the New Relic account for your instance via SSO.

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. Do not change the information in this field. Changing this information breaks SSO integration and prevents you from logging in to your account.

Sample Applications

Java

This sample Java app 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!

$ git clone -b newrelic https://github.com/cloudfoundry-samples/spring-music.git
$ cd spring-music
$ ./gradlew assemble
$ cf push

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.

Ruby / Rails

  1. Add the New Relic agent gem to your Gemfile.

    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.

    $ bundle install
    

  2. 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 and save it to config/newrelic.yml.

    $ wget -O config/newrelic.yml http://docs.run.pivotal.io/marketplace/services/newrelic/newrelic-ruby.yml
    
  3. 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.

    $ cf push
    
  4. Now generate some usage on your app and log into New Relic via SSO as described above; you should see data coming through!

Java

  1. Build your app.
  2. 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.
    $ cf push
    
  3. Now generate some usage on your app and log into New Relic via SSO as described above; you should see data coming through!

PHP

  1. Push the app:
    $ cf push
    
  2. Create a New Relic service instance.
  3. Bind the service instance to the app instance.
  4. Re-stage the app:
    $ cf restage app
    
  5. Go to the app URI and generate some usage data.
  6. Go to console.run.pivotal.io, choose Manage under your New Relic service, and connect to your app data.

Note: To specify the application name which New Relic uses, add a .user.ini 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 .user.ini: newrelic.appname="Virtual Host 1;All Virtual Hosts".

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:

Ruby

  1. Run the following command to set the NEWRELIC_LICENSE environment variable to your license key:

    cf set-env <YOUR-APP-NAME> NEWRELIC_LICENSE <LICENSE-KEY>
    
  2. Edit the newrelic-ruby.yml file obtained earlier as shown below. The following change allows the license_key key to find your license key from the environment:

    license_key: ''
    

Java

Ensure that your existing New Relic service has newrelic in one of its names or tags. This enables the New Relic Agent Framework to automatically configure your application to work with the service.

PHP

Run the following command to set the NEWRELIC_LICENSE environment variable to your license key:

cf set-env <YOUR-APP-NAME> NEWRELIC_LICENSE <LICENSE-KEY>

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:

{
    "newrelic-n/a":[
        {
            "name":"newrelic-14e9d",
            "label":"newrelic-n/a",
            "plan":"standard",
            "credentials":
                {
                    "licenseKey":"2865f6f3nsig8f813af7989fccb24a699cb22a4beb"
                }
        }
    ]
}

For more information, see VCAP_SERVICES Environment Variable.

Support

Contacting Service Providers for Support

Documentation: https://newrelic.com/docs

Create a pull request or raise an issue on the source for this page in GitHub