Monitor and log internet connection up and down times

6 replies [Last post]
Avron

I am a translator!

Offline
Joined: 08/18/2020

I am recently experiencing problems with my internet connection at home. It generally works but several times a day, it is interrupted for a few minutes, so I did not have an opportunity to do significant investigation and I am lacking understanding of what could be happenning. I am only using ethernet with computers so the problem is not wifi.

I am looking for some way to permanently monitor the connection and record down times, in order to get a better understanding of how long the problem lasts each time and how frequent it is. I'd also like a sound alert so that I can do some checking immediately while the connection is down.

Is there any kind of tool in Trisquel repository that could do that?

Magic Banana

I am a member!

I am a translator!

Offline
Joined: 07/24/2010

I am looking for some way to permanently monitor the connection and record down times, in order to get a better understanding of how long the problem lasts each time and how frequent it is.

The systemd journal certainly does that for you. You read it from the terminal with the journalctl command. See man journalctl for the many filtering options (such as -g) the command provides, the different formats for the timestamps (-o short-unix may be convenient if you want to compute the down times using for instance AWK), etc.

I'd also like a sound alert so that I can do some checking immediately while the connection is down.

Once you will have identified in the journal the line that is logged when the connection is down, you can write a small Shell script that calls journalctl every second (for instance) and plays a sound if the line has just been logged. Or, probably easier, instead of reading the journal, the script can regularly call nmcli (with the appropriate arguments; see man nmcli) to figure out if the connection is down.

Avron

I am a translator!

Offline
Joined: 08/18/2020

The only network-related traces I see with journalctl are dhclient and NetworkManager for DHCP lease renewal (I use sudo, I have been using journalctl on my Freedombox and I know that without sudo I see almost nothing), I see no error besides that. The network interface is ok I think, it is just that my ISP's routeur is not responding. I don't know whether it is because it has a problem or whether it is a problem with the cables and switches between my computer and my routeur, or something else, but I'd like to know how frequently it happens and for how long.

Is there any service that constantly checks the gateway? If yes, it is either not started on my computer or it is not logging anything.

If there is not any such servive, my guess it that I could use a script that does some periodic pings, of the routeur and of something on internet (in case the problem is beyond my ISP's routeur). But I don't know whether this is the best idea and if some script exist already for that, it is problem much better than anything I could write by myself.

Magic Banana

I am a member!

I am a translator!

Offline
Joined: 07/24/2010

my ISP's routeur is not responding

Any way to access its logs?

I don't know whether this is the best idea and if some script exist already for that, it is problem much better than anything I could write by myself.

There are many systems made to monitor a whole local network: Cacti, collectd, Icinga, Ganglia, Munin, Nagios, Xymon, Zabbix, etc. Those systems look too complicated for what you want to achieve. I am actually bad at networking...

Avron

I am a translator!

Offline
Joined: 08/18/2020

Thanks. No, I don't have access to the logs.

I looked at ping, the following options seem useful:

 -O     Report outstanding ICMP ECHO reply before sending next packet.  This is useful together with
              the timestamp -D to log output to a diagnostic file and search for missing answers.

The time format is something like "[1636626048.470625]", I suppose there are standard ways to convert it to something human readable.

I guess logging the pings with the above options, plus a process checking the log and alerting would be fine. I would just need to add some kind of logrotation and complete purge if no error.

Since the problems stopped (and I am still struggling with my desktop general protection faults), I did not try to do that, but I'll look at it.

lanun
Offline
Joined: 04/01/2021

You might find this helpful:

https://www.epoch101.com/BASH

andyprough
Offline
Joined: 02/12/2015

Wife, texting: "Let's go out to dinner tonight."
Me, texting back: "Ok I'll meet you at the Vietnamese restaurant at 1636677000".
Wife: "You and your linux nerd friends are stupid."
Me: "Don't be late!"