Thursday, February 3, 2011

Simple internet connection uptime monitor

I need to just monitor how often an internet connection goes down - and for how long. I was going to just write a bit of python that pinged 8.8.8.8 every minute but I thought there must be a util that does this - and produces a nice report

But this is a branch office with a simple SOHO type connection, no SNMP router, Windows only, must run on a desktop machine that isn't dedicated to the task.

Don't need to know capacity, ping latency or anything - just a report of how many times it was down for more than a few seconds to wave at the cable company.

  • i don't know any util but i did myself a simple code for that with perl:

    #!/usr/bin/perl
    
    use Net::Ping;
    use POSIX qw/strftime/;
    
    if (-e '/var/run/net_test.pid') {
            print "net_test already running.\n";
            exit;
    } else {
            system "touch /var/run/net_test.pid";
    }
    
    my $host   = "www.google.com";
    my $ping   = Net::Ping->new('icmp');
    my $result = $ping->ping($host,2);
    
    if ($result != 1) {
            $format = strftime('[%d/%m/%Y %H:%M:%S]',localtime)." Internet is not available...";
            $run = `echo $format >> /var/log/virtua_net`;
            while ($result != 1) {
                    $result = $ping->ping($host,2);
                    sleep 60;
            }
            $format = strftime('[%d/%m/%Y %H:%M:%S]',localtime)." Internet is back...";
            $run = `echo $format >> /var/log/virtua_net`;
    } else {
            $format = strftime('[%d/%m/%Y %H:%M:%S]',localtime)." Internet is ok...";
            $run = `echo $format >> /var/log/virtua_net`;
    }
    $ping->close();
    
    system "rm -rf /var/run/net_test.pid" if (-e "/var/run/net_test.pid");
    exit;
    

    What it does is that it will try to ping google every time it runs and it will then print to a file if it got a reply or not along with the time so you can check later from what time to what time the internet was unavailable.

    If you like it i can make the smalls changes to be used in windows and you did need to install ActivePerl that is all.

    The only changes needed are paths and commands that may be different on windows nothing else.

    mgb : That's pretty much what I would have written (only in python) - I just assumed there was a little systray tool to do this.
    Prix : To be honest i never bothered to look for one eheh but since you were looking for something like this i tought i should share what i use with you/anyone else in the community that would need something alike :) and once again sorry that i don't know of any tool.
    dbasnett : The ping only needs to be to the first router controlled by the ISP, in other words the first device you do not have control of. More and more ISP's are turning off ICMP because of this sort of thing. ICMP traffic to the edge device is OK, but across the backbone is just wasted bandwidth.
    Prix : @dbasnett ofc i changed it to google to hidden to where i ping :)
    mgb : @dbasnett good point - I assumed Google's 8.8.8.8 could handle the load.
    dbasnett : It isn't the load on the servers, though it might be an issue for them. Over 2% of the traffic on the backbone of the internet is ICMP.
    From Prix
  • Try the PA Server Monitor Free edition. It is limited in scope, but the free version will do Ping and create charts for you. Runs on Windows, and as a background service so it won't get in the way.

    mgb : tried it - too complicated to setup. Looks like I will write a bit of python
    From DougN
  • I do this the other way around with Pingdom. Free account, one check. Ping the WAN ip address of the router, and it's all good. You get a monthly uptime report, and you can shout at the cable company.

    mgb : Didn't realise they had a free version. Thanks
  • I am currently investigating a similar problem (a DSL fault at a branch office). I'm running PingPlotter remotely; it's a Windows program and generates a simple to read graph. I've used the graph to tell the ISP what times the link is dropping.

    (Now waiting for ISP to actually fix it - let me know if you have any tips on how to get telcos to work faster!)

    mgb : Sorry - I think that problem is known as NP-very-very-hard
  • Another good choice is http://www.alertfox.com/ .Free website monitoring, transaction tests and reports.

0 comments:

Post a Comment