On 10/01/18 12:46, Mark Rogers wrote:
I have a Pi which is set up with a read-only filesystem, and as such packaged network monitoring solutions aren't happy. Neither wicd nor network-manager like this setup.
A) Can I ask why it's got a read-only filesystem?
I'm not a fan of either, to be honest - for a GUI based PC they have benefits but for a headless box something simpler will suffice.
I have cobbled together a basic bash script that checks to see if it can ping the default gateway and restarts wifi otherwise, but its far from elegant.
Has anyone done anything similar or found any similar scripts online that they use? Ideally, for example, it would be able to "manage" both eth0 and wlan0 (or even wlan1 - in the case of a Pi 3 with an external Wifi added in for better signal strength).
(I'm worried about edge cases with my current script. I can either run in through cron, but that risks it thinking the network is offline just because it hasn't come up yet after a boot which might have bad side effects. I'm currently running it as a systemd service with e network dependency to avoid that, but I'm not sure how that'll work if the network fails to come up after a reboot. Then there's all the things I haven't thought of...)
Monit.
You can configure it to monitor almost anything. It is available to install in the Rasbian repository. It is configured via config files. It can be checked & configured via a web interface. If it finds something not working it can restart it or email you about it or stop checking it. There are many examples on how to configure it (scripts) on-line.
It can take a while to setup, but it's worth it.
Once installed, there are several subdirectories under /etc/monit. These are sample scripts which you can edit or move to enable them (I can't remember exactly how to enable them.). Monitrc has multiple tests all commented out.
Very simple how to install: https://www.digitalocean.com/community/tutorials/how-to-install-and-configur...
Documentation: https://mmonit.com/monit/documentation/monit.html
Specific to network it says:
Network
|CHECK NETWORK <unique name> <ADDRESS <ipaddress> | INTERFACE <name>>|
<ipaddress> is the IPv4 or IPv6 address of the monitored network interface. It is also possible to use interface name, such as "eth0" on Linux.
Monitrc has this commented out test
# check network public with interface eth0 # if failed link then alert # if changed link then alertb # if saturation > 90% then alert # if download > 10 MB/s then alert # if total upload > 1 GB in last hour then alert #
I use mine to check that I can still connect to a remote webcam ip address and many other things.
HTH Steve