Categories
Uncategorized

Tracking Outages

Back in 2004 I found that my ISP had outages where we would not have an Internet connection for a while. That was… a lifetime ago. Well, 16 years ago, anyway. You can see the mention of it in my Connection Report post. I guess I started with checking every 30 minutes, but I eventually changed that to every 15 minutes. As you can see above, I eventually changed it to every 5 minutes because in the last 6 months I’ve seen that we sometimes have very short outages…

And then I thought, why the heck am I looking at connections when I really want to look at “no connections”, so I rewrote the Perl script that’s been running via cron for 16 years to check for no connection instead.

So now I check every minute for an outage, and if there is one, we log it. Now, I know there are more efficient ways to do this, and there’s probably a better way to run this, and there’s probably an open source monitoring solution that will do 100 times what this little script does, but… I don’t care.

Sometimes I care more about hacking together a solution for myself, and messing around with it every now and then, and actually, you know… writing code for the sake of writing code.

Categories
Uncategorized

Internet is up!

Perl

I needed this script last week… See, our ISP had a bit of downtime, roughly 7 hours of downtime actually, but throughout the day there were some periods where our connection would be up for a few minutes before it went down again.

#!/usr/bin/perl

use Net::Ping;

$p = Net::Ping->new("tcp", 2);
$p->{port_num} = getservbyname("http", "tcp");
$host = 'www.google.com';

while (1) {
if ($p->ping($host)) {
print "Internet is up!\n";
# the next two lines will only be useful on osx
$cmd = 'say -v Victoria "Internet is up"';
system ($cmd);
}
else {
print "...\n";
}
sleep(5);
}

To alert me to these few golden minutes of Internet connectivity I whipped up this script. It keeps trying to reach some server (in this example I’m using the highly-available www.google.com) waiting just 5 seconds between each check, and if it reaches the server (meaning our Internet connection is up) it prints “Internet is up!” and on Mac OS X it also says “Internet is up.” I made it say that so I could keep staring at what I was working on and be alerted audibly when the connection returned.

I was tempted to run this on our Mac jukebox so it would announce to the entire office when the connection was up, but by that time things seemed back to normal.

Obviously you could reverse this code to check if a server is up instead of down, and in fact one of my monitoring systems does just that. If you’re ever at the 2XL Networks office and hear “Attention! The server is not responding!” being yelled from one of the Macs… you know there’s a problem.