How to setup New Relic monitoring for your Ghost blog

Adding some sort of monitoring to your website is a good thing, New Relic has a pretty decent offering on their platform. In this post I will walk through how I setup New Relic to monitor this site.

Adding some sort of monitoring to your website is a good thing, New Relic has a pretty decent offering on their platform.  In this post I will walk through how I setup New Relic to monitor this site.

First we have to understand what we want to monitor, then instrument it, then look at the fancy charts or add alerts.

I will be setting up the following New Relic products:

Infrastructure

This will give server metrics like CPU usage and network usage from the host OS

APM

This will give backend metrics like service memory usage and transactions from the NodeJS application service

Browser

This will give browser page load times, and other fancy things like where the readers are coming from.

Infrastructure

The best way to get the Infrastructure agent up and running is to use the "Guided Install" method.

https://docs.newrelic.com/docs/full-stack-observability/observe-everything/get-started/new-relic-guided-install-overview/

Clicking on the Guided Install button from the linked article will automagically open in New Relic your account if you are logged in.

Select your operating system, then a nifty little pre-populated command will pop up for you to copy into the terminal of your server.

curl -Ls https://raw.githubusercontent.com/newrelic/newrelic-cli/master/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY=API_KEY NEW_RELIC_ACCOUNT_ID=ACCOUNT_ID /usr/local/bin/newrelic install

Just follow the prompts and give it the info requested.  Since Ghost uses a MySQL backend database you may as well give the agent access to it when it requests it.  You will then be able to see operations per second and queries per second in the third party integrations.

It will also detect an Nginx install and give you an opportunity to set that up. I needed to add a valid status URL as I usually remove the defaults from a Nginx install.

In case you run into issues, you can look here for tips [That is how I figured out the status URL issue]:

https://docs.newrelic.com/docs/full-stack-observability/observe-everything/get-started/new-relic-guided-install-overview/#troubleshoot

Once installed you should be getting some nice metrics and a few default dashboards.


APM

Now for the fun part.  The APM agent is installed via NPM and then required before the startup of Ghost.

Change to the directory where you have Ghost installed

cd /srv/ghost

Install the New Relic APM agent

npm install newrelic

That gets installed in the node_modules directory, so we need to copy it out to the directory where you have your blog setup.

cp node_modules/newrelic/newrelic.js BLOG_DIRECTORY

We then edit the newrelic.js file with our app name, and New Relic license key.

Next, we edit the index.js file in the BLOG_DIRECTORY/current directory:

nano current/index.js

We add the following to the first line in the file:

var newrelic = require('newrelic');

Finally, we restart the Ghost blog and start sending traffic to it once it is back online.

ghost restart

After a few minutes you will hopefully see some web transactions


Browser

Normally I would have the APM agent auto instrument the Browser agent by injecting the needed JavaScript snippet, but for Ghost we need to do things a bit different.

We have to go to the Browser product page in New Relic, an grab the JavaScript snippet, then copy it into the Code injection settings under the HEADER section.

The New Relic docs explain better:

https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/#copy-paste-app


Once your blog has been online for awhile you can see how it performs and then setup appropriate alerting and notifications.

I hope this is helpful and kickstarts your Ghost blog monitoring journey.