New Relic Application & Server Monitoring for Magento

Written by Peter Davies on .

There a few very simple steps to getting New Relic up and running on your infrastructure:

  1. Sign up for free
  2. Install PHP Module and Server Agent
  3. Test with your application

I was testing this on a client server which was running a busy Magento store and as a result meant that it needed monitoring to make sure that everything was operational all the way through to the checkout. Initially I was confused by what I was being offered but shortly after getting through items 1 & 2 above I soon realised the power of the tool I was being presented with.

Installation - Step 1: PHP Module

The New Relic monitoring system can examine all interaction with PHP; database through to running CRON jobs. This is vitally important to help diagnosing which element of the application is causing issues, and then by diagnostic elimination helps you determine whether it is actually the server at fault (which it rarely is).

First step is to get the debian repository added to the servers sources list:

wget -O - http://download.newrelic.com/548C16BF.gpg | apt-key add -
nano /etc/apt/sources.list.d/newrelic.list

Paste the following in: deb http://apt.newrelic.com/debian/ newrelic non-free followed by updating APT and installing the packlage:

apt-get update
apt-get install newrelic-php5
newrelic-install install

Add the license key when asked and you should see a whole chunk of output but you are really only looking for confirmation everything went well:

Found a valid PHP in : /usr/bin
         PHP Version : 5.3.3-7+squeeze15
  Module API version : 20090626
    Module directory : /usr/lib/php5/20090626
  Zend Thread Safety : no
   CLI ini directory : /etc/php5/cli/conf.d
      Install Status : OK
	  
New Relic is now installed on your system. Congratulations!

Then restart apache apache2ctl graceful for the PHP module to become active. You can now see the module listing if you create a phpinfo(); function call in a script:

Screenshot showing New Relic PHP module

Installation - Step 2: Server Monitoring Agent

Now setup the server monitor: apt-get install newrelic-sysmond

Also adding the key to the nrsysmond.cfg file: nano /etc/newrelic/nrsysmond.cfg
OR run the command nrsysmond-config --set license_key=KEYHERE

Now start the daemon:

/etc/init.d/newrelic-sysmond start

Within a few minutes server data and application data start populating the New Relic control panel (which will obviously have practically no data in it):

New Relic server graph image blank

Testing

Magento is a gigantic application and from our experience it has issues with memory consumption - specifically on low memory machines such as the ones delivered through Rackspace Cloud (admittedly its only low memory based on cost). I've left the system running for a few days and examined the reports.

Interesting use case; On a busy Magento Community store I was looking at the database queries and the site load time when I spotted that the "core_session" table was being heavily used (orange segment):

 

Knowing that this server has SSD (solid state disks) we know that it is quick at read and write operations. After setting the "files" value for session storage in Magento app/etc/local.xml to now use file storage rather the database, we can instantly see a speed improvement on the site from 7 seconds down to <1 second.

And on the server itself the CPU usage and load average dropped off:

We'll leave the site for a while and see how it goes but so far so good! New Relic has definitely helped in this situation, and something I would recommend - although we will need to perform further research to discover why the database was having such issues dealing with simple session storage.