Skip to main content

Setting up New Relic with your Ghost blog

Developers involved with Ghost would be excited and waiting for the release of version 0.5 in which we can expect the ability to install Ghost Apps - aka plugins.

As plugin developers start making awesome stuff for Ghost, one thing that would be affected, is the performance. To avoid this, tools like New Relic could be helpful for developers, to analyse the impact of their apps on the performance of a Ghost blog.

What is New Relic?

If you hadn’t had the chance of using New Relic before, in few words it could described as a sophisticated service to track performance of apps/websites running on different platforms. It supports Ruby, PHP, Java, .NET, Python and recently it also started supporting Node.js; which is what powers a Ghost blog.
Note: Installing New Relic is only possible on self-hosted Ghost installations.

Getting Started

Before we get into the details of integration, head over to NewRelic.com and create a free account. New Relic provides a Pro account for new signups for a limited trial period after which you could continue using your free account to collect basic data.

Next step is get your license key which you can retrieve from your New Relic dashboard when setting up a new App to monitor. Once you retrieve it your key by pressing red button, copy the key and save it as we would need to enter it in next steps.
To finish the rest of the setup, SSH into your server ti finish the remaining steps.

Setting up New Relic with your Ghost blog

01. Navigate to your Ghost installation directory

e.g. cd /var/www/mywebsite.com/ghost/

02. Install New Relic

Now to install New Relic module, simply enter the below command:
npm install newrelic

03. Move New Relic script to your ghost installation folder

Next copy file “newrelic.js” from the new relic folder to your ghost installation folder
cp node_modules/newrelic/newrelic.js newrelic.js

04. Configure newrelic.js file

Edit the newrelic.js file and replace the app_name with a name to identify this site from your New Relic account and also add the licence key that you had retrieved after signing up with New Relic.
Example contents of a “newrelic.js” file.

/**
 * New Relic agent configuration.
 *
 * See lib/config.defaults.js in the agent distribution for a more complete
 * description of configuration variables and their potential values.
 */
exports.config = {
  /**
   * Array of application names.
   */
  app_name : ['MySite.com'],
  /**
   * Your New Relic license key.
   */
  license_key : 'Enter License Key here',
  logging : {
    /**
     * Level at which to log. 'trace' is most useful to New Relic when diagnosing
     * issues with the agent, 'info' and higher will impose the least overhead on
     * production applications.
     */
    level : 'trace'
  }
};

05. Make New Relic start with Ghost

We now have to make the file created in previous step to start with our Ghost site by adding it as a dependency. To do this edit your “config.js” file and add below code on the first line.
require('newrelic');

After adding save and close the file.

Note: In many articles it’s suggested that we add the dependency in either index.js or other files, but by doing so means, you need to edit those files every time you upgrade Ghost.

06. Restart Ghost & start monitoring

The last step is to restart your Ghost site. If there are no errors and if Ghost restarts properly, you would now be able to start receiving data to your New Relic account.

Once all setup is done, you should be able to analyse and test the performance of your website. By taking advantage of New Relic from day 1 of your development, end users could rest assured that the plugins they get from you would work flawlessly.

Buffer

Did you like what you read?

Sign Up and Get Free Email Updates. We won’t spam you; we just want to keep you up-to-date with news about Ghost

Comments

comments powered by Disqus