Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

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:

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.

00:56 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 ping and 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.

01:28 So here, you can see Site24x7, which has tested realpython.com, and not only checked that it’s connected, but also gives individual access times for their various locations around the world.

01:40 This is clearly much more comprehensive than the kind of tool you may program, but it’s an idea of some of the extra features you may want to add in the future.

01:50 Let’s look at some of the technologies you’re going to need to implement for your site connectivity checker. Firstly, requesting web data, probably with the appropriately-named requests module.

02:00 This allows you to programmatically access web content and monitor the results, particularly using the HTTP response code which is accessible using requests.

02:10 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.

02:24 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.

02:57 Now, let’s look at some extra challenges for your site connectivity checker project—the first of which would probably be scheduling, using a library such as celery or apscheduler.

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.

03:36 It’s possible to create a daily list of uptimes and downtimes on any given site and pass these to the user using the same notifications API.

Become a Member to join the conversation.