Keeping your server alive with Monit

NOTE: This is super web/development/sysadmin stuff, casual non website people should probably check this instead

Lately GV has been pretty out of control and our server has been crashing way to regularly due to too many visitors or bots. I’ve been working to find all the little holes in the Apache/PHP/MySQL configurations that are causing the crashes when load gets high, but it’s impossible while you’re constantly putting out fires and restarting the servers manually.

monit logoI’ve been having frustrating fun with a tool called Monit that helps stop your server from completely crashing by watching it’s system stats and selectively restarting processes or executing whatever command you want. It installs pretty easily on Linux servers (I think it’s in both Yum for CentOS/RH and in apt for Debian/Ubuntu) and it uses text files similar to Apache to set up different status conditions and what to do. The configuration took me awhile to get right, but once the percentages were tuned based on watching it for awhile it has kept the server from crashing even once for more than a minute despite some record traffic related to our Mumbai coverage. If it weren’t for Monit I’d probably still be getting calls in the middle of the night saying the site was down.

You still need to find the bugs in your server configuration, or move to more powerful hardware (what we’re doing), but even if its annoying that the apache needs to be restarted every few minutes in order to not crash the server, its better than having it crash randomly when you’re not around. While you’re still tuning the system, you can have it email you based on certain conditions, so you can see how often a certain status is reached and determine whether a restart is necessary. The manual explains the functions pretty well and isn’t too long.

My advice if you’re setting it up

Setting the reset/exec levels

If you’re setting it up for the first time and you’re not having any problems at the moment you should be careful not to set the percentages too high, or the server might crash before it got that bad. I was giving a Memory/RAM max around 80%, but the remaining 20% didn’t seem to be enough to save the server, it was already to late. Here are my settings for our Apache webserver:

check system server1.globalvoicesonline.org
if loadavg (1min) > 5 for 2 cycles then exec "/etc/init.d/httpd restart"
if loadavg (1min) > 7 for 1 cycles then exec "/etc/init.d/httpd restart"
if memory usage > 65% for 3 cycles then exec "/etc/init.d/httpd restart"
if memory usage > 75% then exec "/etc/init.d/httpd restart"

The ‘exec’ action is running the apache restart command directly, which will clear out all appache processes and restart them, freeing up RAM temporarily. I’m also running two levels of Load checking, which will measure the strain on the CPU. Together these cover a lot of situations that result in crashes, and there are two versions of each, one for bad situations that have gone on for awhile (“for 3 cycles” i.e. 3 minutes) and one for terrible situations that are seen even once (“for 1 cycles”, which is actually unnecessary to write).

You can actually also set up monitoring of specific processes like Apache or other servers, but its been a lot buggier (thinks the program’s not running when it is) for me than the raw server statistics, so use at your own risk.

Alternate Email Formatting for Monit

The default email format template that comes with Monit is pretty hard to read to the point where it’s kind of maddening to recieve messages from it. Luckily they offer a custom mail formatting api so you can make one that makes sense for you. The pieces they give you are a bit limiting but I worked out one that is very short and clear and should even work okay as an sms:

set mail-format {
from: monit@yourserver.org
subject: [$ACTION] $EVENT on $SERVICE
message: $DESCRIPTION
– – – – – – – – – – – – – – – – – –
Action: [$ACTION] at $DATE from $HOST

–monit
}

Which sends you emails like:

[exec] Resource limit matched for server2.globalvoicesonline.org
‘server.yourdomain.org’ mem usage of 71.9% matches resource limit [mem usage>65.0%]
– – – – – – – – – – – – – – – – – –
Action: [exec] at Fri, 28 Nov 2008 19:35:22 -0500 from server.yourdomain.org

–monit

Which I think is a lot better than the default. Any Monit users out there with a good format I’d love to see what else you’ve come up with.

Awesome: Global Voices website being shown on CNN!

It’s too bad that GV only gets attention when something horrible happens in a part of the world we cover well (in this case the nightmare attacks in Mumbai), but it’s pretty thrilling to see the site I run and design actually being shown on CNN TV!

global voices website being shown on CNN, photo of a tv

click image for larger version

Thanks to Jules Rincon for her quick reflexes getting this photo of the tv for us all!

Critical Hit: Failblog gets it wrong

list of opposites, someone put noob as the opposite of pro

In case you’re confused, see PurePwnage. I guess the right answer would be ‘anti-‘ but damn, what a dumb one to put in a list like that. My first thought was ‘amateur’…

From the always awesome FAILblog.

Damn, it told me to vote with my heart.

At the risk of distracting any other Canadians from the upcoming U.S. election I thought I’d share this great project, Vote for Environment, that has poll stats for every riding and will give you strategic advice on how to defeat the Conservative government in the upcoming election (the Canadian election). You just put in your postal code and it gives you a recommendation.

My Riding’s Stats
stats for my riding, bloc leads but ndp and green are next, holy shit!

Unfortunately my current riding is utterly pwned by the Bloc Quebecois (seperatist party) candidate Gilles Duceppe, who just happens to be the beloved golden-boy leader of basically the entire sovereigntist movement these days. Vote for Environment was on to this, so they told me to vote with my heart because my vote can’t possibly affect the number of Conservatives in government (though one more bloc rep isn’t so bad, they vote progressive on almost all issues anyway, its just the pesky not wanting to be in Canada that bugs me about them).

My favorite part is seeing the rest of the stats for my riding, the Green party are ahead of the Liberals and the NDP have more than 5x the predicted votes of the Conservatives. If this neighborhood was representative of the whole country I’d feel pretty safe (thanks for ruining everything, western Canada!).

(Thanks, Mira)

Phoques en peril.

An amazing and explosively hilarious skit about the Conservative government’s cuts/reorganization of cultural funding from the perspective of French people in Quebec. Some of it depends on knowing the intricacies of Joual (Quebecois French) but if you follow the subtitles I think it probably plays pretty well anyway.

screenshot of youtube video of cuture en peril

Click the image above to see the video at YouTube.

(Thanks Tim)

PETA v. Jonathan Swift: Modest proposals and the closed-minded dimwits who take them seriously.

peta logoPeople for the Ethical Treatment of Animals

Peta released a new PR campaign yesterday directed at Ben & Jerry’s Ice Cream (emphasis mine):

Burlington, Vt. – This morning, PETA dispatched a letter to Ben Cohen and Jerry Greenfield, cofounders of ice cream icon Ben & Jerry’s Homemade Inc., urging them to replace the cow’s milk in their products with human breast milk. PETA’s request comes in the wake of news reports that a Swiss restaurant owner will begin purchasing breast milk from nursing mothers and substituting breast milk for 75 percent of the cow’s milk in the food he serves. PETA points out to Cohen and Greenfield that such a move on their part would lessen the suffering of dairy cows and their babies on factory farms and benefit human health at the same time.

The fact that human adults consume huge quantities of dairy products made from milk that was meant for a baby cow just doesn’t make sense,” says PETA Executive Vice President Tracy Reiman. “Everyone knows that ‘the breast is best,’ so Ben & Jerry’s could do consumers and cows a big favor by making the switch to breast milk.”

As usual PETA is messing with us to get across a rhetorical point, and as usual all the dumbasses in the world think it’s serious (it was apparrently very poorly recieved on Montreal AM talk radio, which doesn’t surprise me too much).

As a start, this is a refreshing change from their more gruesome campaigns that compare horrible human on human violence from the news (serial killers, maniacs who go on killing sprees, the holocaust) to the human on animal violence that goes on every day in the factory farming system. On another level though it does an amazing job of being a real live satire of itself, and in the process clarifying what it is that PETA is aiming for with these press releases: inflammatory demands that are obviously ridiculous but intended to make people reconsider the “normal” things they do that are actually weird and violent towards animals.

By asking people to consider drinking human milk as part of their regular diet PETA forces us to think about the whole idea of drinking milk after infancy, which is undeniably unnatural and strange even if you enjoy and depend on it. Why won’t you drink human milk? It was designed by nature just for you, unlike cows milk. The only reasonable answer is that it would be uncomfortable and disruptive on the lives of the lactating human females, which just points to the ridiculousness of doing it to cows who can’t even protest their treatment.

hillary clinton eating a babyHillary Clinton eating a baby (source)

To add to the lark, both the tone and the content of the press release seem to directly reference Jonathan Swift’s classic work of satire “A Modest Proposal“, in which he encourages the poor of Ireland to sell their excess babies as meat to the rich to solve two problems at once. Both works draw on a similar cannibalism theme and present an outrageous solution designed to make the reader consider the various relationships at play in a new light.

Obviously you’d have to be stupid to think that Swift was being serious when publishing an argument promoting eating babies, but you’re head is pretty far up your ass if you think PETA actually wants human milk to become a normal product for consumption.

(Thanks for the link, Chris)

Search Engine Keyword stats for the last year: #1 at 7% and 406 searchers…

search engine keywords for the last year
The scariest part is that almost 5% of them were return visitors. Sorry to dissapoint.