1

Topic: monitoring internet connection status.

Hi I have problems with my internet connection being lost every now and then.
this is an issue with my ISP and they should have fixed it.
unfortunately I now noticed it's still happening.
I was wondering if I have some way of monitoring and logging these events so I know for sure when my ISP manages to successfully fixes the problem.

Re: monitoring internet connection status.

What is the device that you are running OpenWRT in?

Re: monitoring internet connection status.

I use this script for the same purpose. (and I did use it before as keepalive/autoreconnect script for vpnc on openwrt). It checks every 5 seconds if it can ping host1 or host2. if it can ping at least one of them everything is fine and it logs "alive ..." in the logfile, of none of the two hosts is reachable it logs "Not alive ...." in the logfile
You might want to increase the 5 sec. I use this quite short intervall because my isp (modem) loses the connection sometimes, and reconnects after 10 sec. So I need a short intervall to get it.
   

#!/bin/sh

host1="www.google.com"
host2="www.orf.at"
while [ 1 ]
do
    if ! [ $(ping -q -c 1 $host1 2>&1 | grep "1 packets received" | sed "s/.*\(1\) packets received.*/\1/") ] ||
          ! [ $(ping -q -c 1 $host2 2>&1 | grep "1 packets received" | sed "s/.*\(1\) packets received.*/\1/") ]; then
       actualdate="$(date)"
           echo Not alive $host1 or $host2, $actualdate >> /tmp/log.txt 
else
actualdate="$(date)"
echo Alive $host1 or $host2, at $actualdate >> /tmp/log.txt #this will fill up ram quiet fast, so maybe you should log "not alive"-events only 
fi
sleep 5 
done

4

Re: monitoring internet connection status.

thanks.
I'll try it when I'll get back home

BTW I have tplink TL-WR1043ND

Re: monitoring internet connection status.

Luci Statistics module has a nice ping application, which will collect the information every 30 seconds and provide charts & database about it.

(Luci module is otherwise ok, but the ping drop rate chart displays 1/100 of the real droprate. see http://luci.subsignal.org/trac/ticket/462 )

6

Re: monitoring internet connection status.

thanks hnyman.
I think I'll try eleon script first.
look simple enough, and I have no need for something more complicated.

7

Re: monitoring internet connection status.

sorry it took me some time to reply.
I'm using your script now and it seems to be working fine.
I've changed the script a bit to suite my needs -

#!/bin/sh

host1="173.194.35.37"
host2="192.118.82.140"
aliveDate="0"
while [ 1 ]
do
        if ! [ $(ping -q -c 2 -w 2 $host1 2>&1 | grep "[1-2] packets received" | sed "s/.*\([1-2]\) packets received.*/1/") ] &&
           ! [ $(ping -q -c 2 -w 2 $host2 2>&1 | grep "[1-2] packets received" | sed "s/.*\([1-2]\) packets received.*/1/") ]; then
                if [ $aliveDate == "1" ]; then
                        echo Alive, at $actualDate >> /tmp/ping_log.txt
                        aliveDate="0"
                fi
                actualDate="$(date)"
                echo Not alive, $actualDate  >> /tmp/ping_log.txt
        else
                actualDate="$(date)"
                if [ $aliveDate == "0" ] ; then
                        echo Alive, at $actualDate >> /tmp/ping_log.txt
                        aliveDate="1"
                fi
        fi
        sleep 5
done

I don't need it to log all alive times but only last alive time before it disconnect
and when it reconnects.
also if one of the hosts is up I'm considering the connection as active and not only if both of them are up.
last I saw that when the connection is lost, the ping command will take way too long to timeout (almost a minute)
so I changed it to send two packets but to stop after 2 sec
only when no packets returned the connection will be considered as lost.
for this to work properly I had to use the hosts IP address instead of the domain.
I saw the response for lost connections were still really slow, and after almost loosing my mind I figured the ping command
first resolves the host which might have a long ttl by its own and will delay the entire process

thanks for the help

Re: monitoring internet connection status.

Oh thanks for the correction, this was my intention, too. To log only if both host aren't reachable.

9 (edited by lb_le_coyote 2017-05-19 08:58:37)

Re: monitoring internet connection status.

Hello,

Thanks a lot for this script.
I've changed it a little bit to only monitor 1 host and to get a file by day



#!/bin/sh

host1="109.xx.yy.zz"
aliveDate="0"

while [ 1 ]
do
date=`date "+%Y-%m-%d`
if ! [ $(ping -q -c 2 -w 2 $host1 2>&1 | grep "[1-2] received" | sed "s/.*\([1-2]\) received.*/1/") ] ; then
if [ $aliveDate == "1" ]; then
echo Alive, at $actualDate >> /perso/log_wan_$date.txt
aliveDate="0"
fi
actualDate="$(date)"
echo Not alive, $actualDate  >> /perso/log_wan_$date.txt
else
actualDate="$(date)"
if [ $aliveDate == "0" ] ; then
echo Alive, at $actualDate >> /perso/log_wan_$date.txt
aliveDate="1"
fi
fi
sleep 5
done