How-tos

New Relic performance monitoring for Node.js apps

Share this post:

The SDK for Node.js buildpack now contains better integration with the New Relic service in Bluemix.

When an app is bound to an instance of the New Relic service, the buildpack recognizes this based on the VCAP_SERVICES environment variable. It will then set the NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY environment variables, which are recognized by the New Relic agent, for you. If you manually set these environment variables the buildpack will not override them.

Follow the steps below and you’ll be monitoring an app in no time!

Create the app

    1. Change to an empty directory and copy the following code into a file named package.json. This adds a dependency on the New Relic agent’s npm module.
      <code>
      {
          "name": "myapp",
          "version": "0.0.1",
          "private": true,
          "scripts": {
              "start": "node app.js"
          },
          "dependencies": {
              "express": "4.13.x",
              "cfenv": "1.0.x",
              <b>"newrelic": "1.30.3"</b>
          },
          "engines": {
              "node": "4.x"
          }
      }
      </code>

 

    1. Then copy the following code into a file named app.json. This is a simple Express-based app. Notice how the first thing we do is load the newrelic module.
      <code>
      <b>require('newrelic');</b>
      
      var express = require('express');
      var cfenv = require('cfenv');
      
      var app = express();
      var appEnv = cfenv.getAppEnv();
      
      app.get('/', function (req, res) {
        res.send('Hello World');
      })
      
      app.listen(appEnv.port, '0.0.0.0', function() {
        console.log("server starting on " + appEnv.url);
      });
      </code>

 

  1. Optionally use environment variables or a newrelic.js file in the root of the application to change the default agent configuration options.
    <code>
    exports.config = {
      logging: {
        level: 'trace',
        filepath: 'stdout'
      }
    }
    </code>

     

    See config.default.js for all the configuration options.

  2. Finally, push your app to Bluemix.
    <code>
    $ cf push &lt;app name&gt;
    $ cf create-service newrelic standard &lt;service instance name&gt;
    $ cf bind-service &lt;app name&gt; &lt;service instance name&gt;
    $ cf restage &lt;app name&gt;
    </code>

Monitor the app

Wait a few minutes after your app starts for the data it generates to be reported, then open the New Relic Dashboard from within the Bluemix UI. From here you will automatically be logged in to the New Relic UI.

In the New Relic UI click on your application and you will be able to see your metrics like the web transaction time.

screen-shot-2016-09-29-at-4-17-45-pm

For a good summary of what the different metrics are see A Quick Guide to Getting Started with New Relic.

Add Comment
No Comments

Leave a Reply

Your email address will not be published.Required fields are marked *

More Compute Services Stories

Think, write, submit: New ideas portal for IBM Cloud

IBM Cloud is excited to announce a new system for submitting ideas for IBM Cloud Platform (Bluemix) and Services improvements. This new system will drive faster decisions and deliver better visibility for your ideas. It is an integrated and automated feedback system to connect your ideas with IBM product and engineering teams.

Continue reading

Vulnerability Advisor – Secure your Dev + Ops across containers

Vulnerability Advisor reports provide a convenient way of quickly knowing if it’s safe to deploy an image in Bluemix. But what if it's already running? This post introduces the Live-scanner service for evaluating running containers in Bluemix.

Continue reading

Bringing the power of GPUs to cloud

GPUs are very efficient at manipulating computer graphics, image processing, and other computationally intensive high performance computing (HPC) applications—not to mention they have a major performance advantage. This is the reason Bluemix brought these capabilities to a broader audience.

Continue reading