Presentation: NewRelic RPM and Drupal
I was invited to give a talk on the NewRelic application monitoring platform by the Los Angeles High Performance Drupal group on Feb 7th. The general idea was to describe how NewRelic can provide targeted debug and performance details on a running Drupal site. The video is linked below, and I followed it up with additional details both in the linked thread on the Drupal groups site and below.
1) How does the NewRelic PHP extension communicate?"
There is a system daemon called newrelic-daemon that is installed. This daemon, which is started as root on my system from the standard system startup scripts, looks in /etc/newrelic/newrelic.cfg. The config file specifies the license key, collector host, whether or not the traffic sent to NewRelic should be SSL encrypted or not (default: no), and an optional location for the socket. By default, when the newrelic-daemon is started it creates a socket in /tmp/.newrelic.sock. The purpose of this daemon and socket is to receive information from the PHP extension and forward it along to the NewRelic servers.
The NewRelic extension is loaded into the php interpreter in the same manner as your other extensions (apc, curl, pdo, mysqli, etc.) The newrelic.ini file that controls the loading of the extension and configuration options supports a setting "newrelic.daemon" which specifies the socket location (again by default it knows to look in /tmp/.newrelic.sock.) So that's the answer as to how it all fits together - the daemon starts and creates a socket, the php extension sends information to the socket, which is picked up by the daemon and sent via port 80 back to the NewRelic collector server.
2) Why can't I easily configure NewRelic for multiple sites when using Nginx with PHP+FCGI?
There is a configuration page detailing how this should work here. After following the instructions, I had properly configured daemons, with one NewRelic socket per site /tmp/.newrelic_site1.sock and so forth. So far so good.
Next I moved on to the per-directory INI settings documentation page here. Using nginx, I changed the fastcgi_param PHP_VALUE "newrelic.appname=My Blog" and that worked fine. However, when I went in to have a look at phpinfo(), I saw this:
... and I saw failure messages in the log. I thought "gee that should be easy enough to fix, I'll just do this":
BZZT, nope. That doesn't work. I can restart Nginx and the php-cgi process but no soup for me. The setting does not change. Why? Because the php newrelic.daemon setting falls under the SYSTEM scope per this documentation page. And you can't override SYSTEM settings at runtime, only via the php ini file.
I opened a ticket with NewRelic about this. My goal was to configure one daemon+socket per website, but I can't do a runtime configuration specifying where to point the socket (either in the nginx config file or via ini_set()).
The other answer may be to use per-directory settings for php-cgi, or run one php-cgi per site with different php.ini files. I mention this here because the online documentation was not clear about this and was somewhat misleading. It may have been updated by now after my ticket, but just changing newrelic.appname is not all that you might need to do.
3) How can I integrate Drupal with NewRelic?
There is a NewRelic Drupal module that builds some additional integration with the service. One of the other things you can do with NewRelic is to mark a point in time when you deploy. So for example, let's say you update a module on your site. You can report that deployment to NewRelic and it will draw a line on all of your charts. This is very helpful when trying to determine the impact of a change you made to the site. The Drupal module allows you to very easily create and push a deployment note. You could do this with cURL and the command line but the module makes it quite easy. I recommend it if you are going to roll out NewRelic.
4) Where else can I learn about NewRelic?
Lewis Cirne, CEO of NewRelic, did an interview in December at the CloudBeat conference. Here's the video. It's worth watching if you are interested in learning about NewRelic from a non-technical viewpoint. He outlines quite a bit about their vision for building the company and their philosophy.
Last but not least - if you have additional questions feel free to post a comment or send me a tweet. I'd be happy to reply with more details if I missed something.