Site Connectivity Checker
Here are examples of a site connectivity checker you can use for inspiration:
Here are resources that you can use to build your site connectivity checker:
- requests: An elegant and simple HTTP library for Python, built for human beings
- Making HTTP Requests With Python Real Python video course
- sqlite3: A self-contained, serverless, transactional SQL database engine
- Introduction to Python SQL Libraries: Real Python article
- celery: Distributed task queue
- apscheduler: In-process task scheduler with Cron-like capabilities
00:00 Site Connectivity Checker. When you visit a URL, you expect to get the requested pages on your browser, but this isn’t always the case. Sometimes the site can be down and you won’t get what you’re looking for.
00:11 Instead, you’ll get an error message. You can keep trying a site that’s down until it comes back up, and then you get the information you need. This is where a site connectivity checker project comes in.
00:22 It visits a URL and returns the status of that URL: whether it’s up or not. The site connectivity checker will visit the URL at intervals, returning the results of each visit. A site connectivity checker can automatically check the status of a site, store this information over time, and allow you to monitor when the site is up or down, automatically.
00:43 Let’s take a look at a couple of implementations of site connectivity checkers, the first of which is a simple command-line tool which is included with most operating systems, and the second of which will be a fully-featured web-based implementation.
So as we can see here, we’re in the terminal—in this case, on macOS, but this will work across Windows, Mac, and Linux—and it’s the
ping command. Here, you can see I’ve entered
realpython.com, as that’s the site whose connectivity I wish to test. As you can see, I’ve had a reply every second, and it also gives us the number of milliseconds between the request and the response. It’s a simple, basic check for connectivity to any given site.
Secondly, you need a way of storing the results, possibly using the
sqlite3 module to create a database. This can store all of the results from the
requests module, and that will allow you to perform analysis on the site’s performance over time.
Reporting. You’ll need to decide whether or not your program is going to report constantly back to the user, as we’ve already seen with
ping, or whether it will store the results and then need them to be analyzed later on. You’ll need a method of adding sites, whether this is by changing a configuration file or by using command-line parameters. And, you’ll need a way to modify the check intervals to stop overwhelming sites with needless request data and creating data which is unnecessary. After all, you may only need to check the site every few minutes, rather than every few seconds.
03:08 You’ll be able to make this run in the background and create data over a long period. This will allow you to build a more accurate picture of how reliable a given site is. Secondly, notifications.
03:19 Many notification systems on smartphone and web offer APIs allowing you to programmatically create notifications from your application. This will mean that your user will know straight away when a site is up or down and can act accordingly. The same goes for reporting.
Become a Member to join the conversation.