Are there any production-ready Elixir libraries for managing internet connections, similar to monitor-internet-connection.py?
What would make it âproduction readyâ for you? If it is about reliability, a Genserver under a Supervisor would do.
The Python versions is not an example of defensive code style; which it could use for this use case as you donât want your monitor to go down (and yes, it did see the generic OSError handler). I assume it is expected to be wrapped in try/catch in the using code. If one fails to do so, it seems is can bring the whole program on itâs knees.
You may simply run this module in a console/terminal and leave it running for days/weeks on end.
The Elixir version doesnât have to be written defensive due to the Supervisors. Even when is sucks (which is given the limited use case almost impossible), it would not take the whole program out with it.
So even a simple Elixir version is more reliable than the Python version. You could replicate the py-file within an hour with benefits of OTP. For me that would be instantly production ready.
The Elixir version run for years on end without any problems.
ps. I highly doubt this would ever be an Elixir lib. Maybe a Gist is a better fit as itâs only one file and there is no need for advanced coding in Elixir to accomplish this.
Interesting proposition. Say a particular internet connection goes down how would I go about cycling through other available connections until it finds a stable one? (Iâm on an Ubuntu machine.)
What is a stable one? Stable is not objective so hard to say without knowing your interpretation of âstableâ.
Having my fair share of connection related code, I can assure you that no connection ever can be assumed to be âalways connectedâ. As Erlang (where Elixir is build upon*) was build with exactly that in mind, Elixir is the perfect language to build the monitor with.
*keeping it simple
I appreciate you asking. Iâm referring to a connection that stays active as opposed to one that finds it challenging to stay connected to the internet. It would be ideal if the system could immediately switch to a different network the moment it detects that the current connection has failed, makes sense?
I guess I"m sort of confused about the kind of system youâre talking about. When do programs you write manage connections and switch between âconnectionsâ? Most of the time servers have exactly one public internet connection, can you elaborate on the circumstances youâre designing a program to operate within?
Me too
My first thought was some sort of scraper that is getting IP banned but in that case youâd just retry or log (and defer to another instance) on failure.
(internet-connection.py) is a Python module to monitor the uptime of the Internet connection - that is to say to monitor that an external IP address is always reachable.
If itâs a specific IP address that you want to check (i.e not your own connection but uptime of some ip/url) then you could build a small Phoenix app to do it. I made something similar in Ruby some years ago when a leading domain registration company failed to register a domain even tho the payment and all confirmation emails went through as usual - they said it was in their terms that we had to verify domains had actually been registered ourselves!!! It was a client domain and it cost us a lot of money to get back so I built a small app to check our domains once a day and then send us an email if they didnât resolve or resolve to the correct IP (and/or didnât show specific content we were expecting). I was actually planning on converting it to Phoenix app one day and offering it as a service as it would be a perfect fit for Elixir due to the sheer amount of domains that might need to be checked.
For general uptime checks you could do similar, just check every minute and log successes and failures.
If my WiFi connection dropped, how would I go about restarting it from within the Elixir app?
It seems you donât need (not even should want) a lib/app for this but some OS specific config. I know our office MacBooks have one as the Wifi stack of MacOS isâŠ.surprising. Ubuntu probably has some (low level) settings for it too.
- Connects and disconnects of interfaces is logged by the OS.
- When you want to track an external server, Elixir can do so. But it wonât manage the interfaces as thatâs the job of the OS.
You can combine both to check what was the cause of the âunreachableâ error (logging).
Why do you need to do that tho Max? Usually if your Wifi connection drops your OS will reconnect. Are you serving an app from your home machine? (Not a great idea, you may be better off using a free-tier of one of the Elixir-specific hosts.) Or is it some script youâre running? (If so can you just pause it or set to retry until your OS reconnects you to the network?)
Thanks for the suggestion. Which would you recommend?
These two come to my mind:
https://www.gigalixir.com/
https://fly.io/
Wow, that pings google once per second⊠I know they are a friendly bunch and eat the bandwidth cost for this, but thatâs quite a chunk of bandwidth !!
Then you realize Google owns Youtube and serves 4k-resolution videos. They wonât even notice when they look at their data usage with a microscope
Just for fun the statsâŠ
https://everysecond.io/youtube
When a client sends a DNS query to your DNS server, normally the packet length is between 50 and 550 bytes (including the IP header). So in worst case, the script will consume 47.52 megabytes per day.
The average video length is 11.7 minutes. A 1080p video Youtube uses 5mbps. This makes the average video consume 412.5 megabyte of data for one single view.
So in the worst possible scenarion, a single view of an average 1080p Youtube video consumes 9 times more data then the script in a whole day. Factor 10 for the scenario in which the DNS connect only takes 55 bytes.
The worst case scenario would be 1.2762029e-8% of their outgoing traffic!
When the whole world population would use the script, it would cost them 368,280 terabytes per day. That would make a dent: it comes close to the 440,000 terabytes Youtube uses per day.
But rest assured, one can run the script 10,476,190,500 days (28,701,891 years) before it has used one day of Youtube data. I bet the connection drops before that ever happens
Ps. I know CDN, ISP cache, upload vs. download, math is hard etc. Letâs get back on topic