Want Some Campfire With That Bluepill
This is a seriously old post. I’d probably not bother reading it, but I keep it here for nostalgia.
Custom Triggers With the Bluepill Monitoring Gem
We use Chef for automating our server infrastructure, but I’ll show you the manual way of installing Bluepill (either locally or remotely) so you can play with it.
1
|
|
That wasn’t hard, was it? Dependencies will be resolved, and installed too. Now we’ve got it installed, let’s take a little look at the commands we can give it.
Check the status of all applications and processes
1
|
|
Start all applications and stop all applications, or a single group.
1 2 3 |
|
Quit Bluepill.
1
|
|
You configure Bluepill with a configuration file. Here’s one we use to start multiple resque queues. It’s a work in progress but does what we want for now. I won’t explain the config file because there’s plenty of blogs (and of course the Bluepill README) that go into detail here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
What I wanted to add was a notification system that let me know when things had gone horribly wrong. Specifically I wanted Campfire notifications, as that’s where all the cool techies at PharmMD hang out.
For notifications, Bluepill allows us to write simple ‘Triggers’. These triggers can be added to a process in the config file, like zoh:
1
|
|
So let’s add a Campfire notifier. First things first, I’ll be using the tinder gem to talk to Campfire, have a look at their README for details on how it works (or the excellent tinder homepage). Install tinder.
1
|
|
At the top of the Bluepill config file (anywhere above the application block) add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
In the initialize
method I set up some parameters that I can pass in, as well as provide myself with some defaults to fall back on.
1 2 |
|
I create instance variables for each option for access later on, and call super to allow the Bluepill::Trigger class to do its own initialisation.
1 2 3 |
|
Next up I create one of the required methods that Bluepill will call periodically and sprinkle in a little logging (@logger
is provided by Bluepill::Trigger).
1
|
|
Next up we wrap our Campfire notification in a rescue block, because we don’t want ay silly exceptions like a lack of net access from bombing Bluepill out. There are a few transitions we can use, the important one for me is when a process dies (even though Bluepill will restart it), I want to know when that happens so I can find out why and stop it.
1
|
|
Tinder makes campfire access so simple. Connect to campfire, select a room, and then ‘speak’ into it.
1 2 3 |
|
That’s it for the trigger. Now all we need to do is tell the process that it should fire that trigger. Add the following to the process block just beneath where we checked for memory usage.
1
|
|
That’s it. Now when you load the config file in, Campfire will get notifications if the process needs restarting.
Simple Campfire notifications using Tinder and Bluepill? Done.