"Doing things the right way is hard, which is why most businesses take the lazy path and settle for mediocrity. People respond to quality, though: they reward it, in no small part because quality is such a rarity in today’s marketplace. Do right by your customers and they’ll do right by you."
Since switching from a spawn-fcgi implementation several months ago, I’ve been really pleased with PHP-FPM. Given some of the new statistical features included in newer versions (5.3.2+), I put together a plugin suite for Munin. I am not proficient in Perl so I encourage feedback and suggestions to make these better. This suite contains plugins to measure average process size, total memory usage, connection count, process count and most importantly, pool status.
Before installing, make sure you have the most recent version of PHP-FPM:
[www-data@lenny:/var/www]# php-fpm -v
PHP 5.3.2-1ubuntu4.5ppa5~lucid1 (fpm-fcgi) (built: Sep 22 2010 08:04:01)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
Now we can get into our plugin directory, clone the plugins from my Git repo and make them executable:
To enable the plugins, you’ll need to create these symlinks:
Note: For the phpfpm_status and phpfpm_connections plugins, you’ll need to enable the status feature included in newer versions (5.3.2+) of PHP-FPM. Open up the php5-fpm.conf, in /etc/php5/fpm, and uncomment line 186 for the pm.status_path directive:
Jérôme Loyet from the Nginx forums provided some useful insight on how to get this working with Nginx. You’ll essentially set up the status location directive like this:
You’ll need to make sure that from within your box, you can curl /status with # curl http://localhost/status. You should get a response similar to this:
Once the plugins have been set up, you run any of the plugins manually using the munin-run command line tool:
The output should look like this:
Note: The phpfpm_status plugin is particularly useful if you’re using dynamic process management. You can choose static or dynamic in the php5-fpm.conf.
Rails 3.0 is ponies and rainbows! Well, kinda. I've never been into Rails much but 3.0 has brought on some much needed features over previous versions, some of which deserve bullet points:
Brand new router with an emphasis on RESTful declarations
Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
The newest version of Rails came out on August 29 so I decided to jump right in. Since Ruby 1.8.6 and earlier are no longer supported, we'll be using RVM in this article. RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems.
Before we get started, we'll be using a fresh (ve) Server from (mt) Media Temple running Ubuntu 10.04 Lucid Lynx for the install. I should also note that we're not installing a full-featured application -- this is simply a tutorial on how to get the Rails 3.0 test application up and running with Nginx + Passenger.
Prerequisites: You'll need these to get through the entire install process for RVM, Nginx and Phusion Passenger (mod_rails).
Now we'll need to do a system-wide install of RVM. For your convenience, the dude that wrote RVM provided a script you can run on most that does all the heavy lifting:
Every piece of documentation and website I read on this had this particular part wrong. I've updated the correct path from the documentation for the purposes of this article:
Doing so ensures RVM is loaded as a function (versus as a binary), ensuring commands such as rvm use work as expected. Please note that you can confirm this worked correctly by opening a new shell and running:
If this was performed correctly, you should see:
So if that looks good, we can continue installing Ruby:
Now sit back and relax. This took about 8 minutes on my system. To make sure that the system uses this version, we can use RVM for this and install the rails and passenger gems:
Now comes the fun part of installing Nginx. This will grab the stable binary, bake in Phusion Passenger and compile it:
You will be presented with two options right from the start. Just choose Option 1 and let passenger download, compile and install Nginx for you. You'll also be prompted to choose a prefix directory. You can leave it as the default, /opt/nginx. When it completes, it should give you some Nginx configuration snippets for your rails apps. Save those as you'll need them later.
Now, you'll want a init script so you can stop/start/restart Nginx. I've provided mine here:
We're almost done. Now we can create the test application:
You'll need to update the Nginx configuration to make sure it's using the right document root now. The file will be located in /opt/nginx/conf/nginx.conf:
The spacing looks a little weird in that middle sed command for a purpose -- to keep the syntax of the nginx.conf file consistent. Now that we've restarted Nginx, we should see the 'Welcome aboard: You're riding Ruby on Rails!' image:
If you're interested in an all-in-one installation, I've put together the steps above into a simple bash script. Enjoy!
I love Wilco. I also love Coffee. So when the coffee-connoisseurs Intelligentsia teamed up with Chicago-based band, Wilco, to offer an exclusive Wilco/Intelligentsia co-branded mug, an impulse purchase was made.
If you're interested in purchasing one, head over to the Intelligentsia store.
If you're like me, you want to monitor and graph every little piece of your server. Until recently, I've been relying on a simple PHP script to display APC statistics. Although the tool worked well, I wanted to integrate the statistics into Munin, as most all other server properties and system services are monitoring with it. The problem was that finding a suitable APC plugin for Munin proved to be very difficult. Fortunately I stumbled across this German gem (Vielen Dank, dass Sie meine deutsche Freundin!) that met my needs. To set this up on your system, just follow the directions below:
First, let's set up the apcinfo.php file in the document root of your web server and retrieve the file from a private gist:
Now, make the file executable:
The script itself is very simple. It simply ouputs the total cache memory, memory available and memory used:
To confirm that the script is working, check out /apcinfo.php on your site. You should see something like the following:
Now, let's set up the Munin plugin that will use that information:
What that does is create the apc plugin, makes it executable and then symlinks it to the proper directory. Now, we'll need to make sure Munin loads the new plugin. To do this, we'll edit the /etc/munin/plugin-conf.d/munin-node to add the following:
Obviously, you'll want to replace example.com with the host you intend to use. Once the file has been updated and saved, restart Munin:
Once the node is running, it'll take a few minutes for Munin to update so don't worry if you don't see any new graphs right away. One thing to keep in mind is that you will need the LWP::UserAgent Perl module. If you are on a Debian/Ubuntu OS, just run the following to install it: