Editor’s note: This post is adapted from an original post on Matt Brunt’s blog in early March.

New Relic is a fantastic monitoring tool. Hiawatha is a fantastic Web server. Let’s get them playing together, shall we?

New Relic offers great tools for monitoring your servers, apps, and related data. The full versions can allow detailed histories, logging, and detailed analysis of slow queries and such, so if there’s an issue with your servers or apps, you can more 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.

Hiawatha is a lightweight, secure, and high-performance Web server written by Hugo Leisink since 2002. It contains features and functionality that either don’t exist in other Web servers, or are available only as extra modules requiring additional configuration and set up.

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

Installation and prerequisites

  1. Install Hiawatha! Installation instructions can be found here (although if you’re reading about how to get New Relic working with it, you probably already have it installed).
  2. Install PHP FPM. That’s usually as simple as apt-get install php5-fpm or yum install php5-fpm or whatever flavor your distro uses.
  3. Install New Relic and get it set up with your keys. Installation instructions can be found here.

We’ll be using a different PHP FPM socket for each host. That way you can set the app name differently for each host if you’re running multiple sites on a single server. But 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

Note: In the files below, replace ‘mysite’ with your own site / app name.

You’ll probably have a line (sometimes 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 the existing values if needed):

; Start a new pool named 'mysite'. 
; the variable $pool can be used in any directive and will be replaced by 
; 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 will 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 to 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.

That should be it, though 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.

Being able to look at the breakdown of requests has given me much better insight into where potential bottlenecks of the site might show up. I can more easily track how response times are handled as traffic scales (or when I’m load-testing a site). All while being able to use my favorite Web server!

Matt Brunt is a UK-based Web developer, nerd, techy, and lover of tea and jaffa cakes View posts by .

Interested in writing for New Relic Blog? Send us a pitch!