Debugging web applications can be tricky, especially when they are deployed to a production environment that you can't reliably reproduce in development. This difficulty has been addressed by companies such as New Relic. New Relic is a software analytics company offering powerful server and application-monitoring tools for developers that chart performance and resource usage across a web applications in real-time. Their Software-as-a-Service (SaaS) solution monitors web and mobile applications running in cloud, on-premises, or hybrid environments.
This tutorial covers how to integrate New Relic analytical tools into a Node.js AppFog application.
CenturyLink AppFog is our Platform-as-a-Service (PaaS) offering based on Cloud Foundry. It allows you to easily host cloud-native applications without worrying about provisioning or maintaining servers and separate services. AppFog applications deploy quickly and scale automatically while having access to the full range of CenturyLink Cloud products.
New Relic is a full-featured software analytics product delivered in a SaaS model. Their software is built to monitor web applications running in many different environments, including the cloud.
Before We Start
If you don’t have a CenturyLink Cloud account yet, head over to our website and sign up for a free trial. You’ll need it to access AppFog.
This tutorial works best with an existing Node.js application. In addition, New Relic reports contain more interesting information if your application is using external APIs. If you don't have such an application handy, walk through our tutorial series on creating a Node.js application with AppFog.
- Part 1 - Store and Authenticate User Credentials
- Part 2 - Build a Document Storage System
- Part 3 - Include Powerful Search Capabilities
- Part 4 - Add a Customized PDF Viewer and Comment System
- Part 5 - The Next Step for Your Web Application
You also need to have a New Relic account. Go to their sign-up page and start with a 14-day free trial.
Getting Your New Relic License Key
Your New Relic license key is needed to register a new application and begin monitoring it. Follow the instructions below to find your New Relic license key.
- Sign into your New Relic account.
- From the Account drop-down menu in the upper-right corner, click Account Settings.
- Your license key will be in the right-hand column. Save it for later.
Adding New Relic to Your Node.js Application
Integrating the New Relic agent into your Node.js is fairly straightforward. The instructions provided when you go through their sign-up process will not successfully add their library to your AppFog application, however. Instead, follow the directions below.
- In your Node.js project directory, run the following commands.
npm install newrelic --save cp node_modules/newrelic/newrelic.js
- With a text editor, open newrelic.js.
- Find the line starting with
app_name:and replace the string "My Application" with a descriptive name for your Node.js application.
- Find the line starting with
license_key:and replace "license key here" with your New Relic license key.
- With a text editor, open your Node.js application's main module file.
- Add the following before the first line of code in that file:
- Deploy your modified application to AppFog with the following command.
Monitor the output from the
cf pushcommand to ensure that the New Relic library has been installed in your AppFog application.
Analysis tools from New Relic are now monitoring your AppFog application.
Using New Relic Reports
It may take a few minutes (typically, about 5) for your application to start sending data to New Relic. Once your application is sending metrics, follow these instructions to obtain New Relic reports.
- Sign-in to your New Relic account.
- Click on your application name in the application list.
- From the application dashboard, you can reach a number of informative reports. For instance, click External Services in the left-hand column to see a report detailing external APIs used by your application.
Once you have access to real-time metrics on your application's performance, you are on the road to optimization. New Relic offers many different features. Be sure to check out their Node.js Agent documentation. They also offer agents for most programming languages supported by AppFog. Check out the full New Relic agent documentation for more information.
Sign-up for our Developer-focused newsletter CODE. Designed hands-on by developers, for developers. Keep up to date on topics of interest: tutorials, tips and tricks, and community building events.
We’re a different kind of cloud provider – let us show you why.