Hiawatha & New Relic

Hiawatha & New Relic

New Relic is a fantastic monitoring tool. Hiawatha is a fantastic web server. Let's get them playing together shall we?

New Relic is a great tool for monitoring your servers, apps and related data. With premium versions allowing detailed histories, logging and detailed analysis of slow queries and such, it means that if there's an issue with your servers or apps you can easily find the root cause without having to go manually digging through logs. Not only that, there's mobile applications and notifications if things such as transaction and app-response time go over a certain threshold. (Plus, they often give t-shirts and freebies for new signups! Free stuff!)

This is a list of basic instructions & steps on how to get Hiawatha and New Relic working - or at least, how I've done it. There may be other ways, but I've not explored them.

Installation & Prerequisites

  1. Install Hiawatha! Installation instructions can be found here (though I assume if you're here looking for info on getting New Relic working with it, you may already have it installed)
  2. Install PHP FPM - usually as simple as: apt-get install php5-fpm or yum install php5-fpm or whatever flavour your distro uses.
  3. Install New Relic and get it setup with your keys. Installation instructions can be found here.

We'll be using a different PHP FPM socket for each host, this way you can set the app name differently for each host if you're running multiple sites on a single server - this obviously means you can't overload your server with loads of PHP FPM pools if you've not got the resources available for it - be sensible!

Setting up a new PHP-FPM Pool

In files below, replace 'mysite' with your own site / app name.

You'll probably have a line (sometimes at the at the end) in /etc/php5/fpm/php-fpm.conf that includes all files from /etc/php5/fpm/pool.d/*.conf - if not, add it:

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf

Add a new file in the /etc/php5/fpm/pool.d/ directory for the pool we're creating. You can copy the existing one as a reference (it's usually /etc/php5/fpm/pool.d/www.conf)

In file /etc/php5/fpm/pool.d/mysite.conf make sure you have the following (change existing values if needed):

; Start a new pool named 'mysite'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('mysite' here)
[mysite]

listen = /var/run/php5-fpm-mysite.sock

php_value[newrelic.appname] = 'My Site Application Name'

Configuring Hiawatha

In our Hiawatha configuration file /etc/hiawatha/hiawatha.conf we'll add a new FastCGIserver that'll connect to our new php-fpm socket:

FastCGIserver {
    FastCGIid = php5-fpm-mysite
    ConnectTo = /var/run/php5-fpm-mysite.sock
    Extension = php
}

Then in your vhost for the site we'll need tell it to use the new FastCGIserver we've specified above:

VirtualHost {
    # Your other vhost configuration options go in here too

    UseFastCGI = php5-fpm-mysite
}

Once this is done, you can restart PHP-FPM and Hiawatha:

$ /etc/init.d/php5-fpm restart
$ service hiawatha restart

Make some requests to your site that you've added this for, then if you look in New Relic, you should start to see data coming through as a new Application in the "APM" section.

I think that's all the steps required! I'm writing this after the fact...

As a note: I had to update my CSP for the site as well. I've added *.newrelic.com bam.nr-data.net so that New Relic could run the JS it requires.

EDIT: This post has been adapted and posted on the New Relic blog too!