Raspberry Pi 4 Website Up-Time Monitor

In summary: I guess that depends on your definition of "real-time". If you are wanting to track the uptime of a website, a simple ping every second could be considered real-time.
  • #1
19,443
10,021
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
 
  • Like
Likes QuantumQuest and sysprog
Physics news on Phys.org
  • #2
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
 
  • Like
Likes sysprog
  • #3
fresh_42 said:
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
Won't do anything "real-time". Just a simple ping every second.
 
  • #4
For that even Pi Zero would be an overkill.

At the moment I have five Pi running (I think 2, 2, 3, 0, 0, not entirely sure about exact models). One for automatic backups (about 2 MB per day, so a 64GB SD card will most likely survive me), one for monitoring the street outside, one for my weather station, one for my birdhouse and lately testing one as an NFS with a mechanical HDD attached. NFS is way too slow for any serious application, but I hope it will solve a recurring problem with the street camera - it fills 32 GB in a week (rotating the data) and kills a 32 GB pendrive in about 2 years (typical flash memory doesn't survive more than about 100 writes).

I am not saying these are all I have :wink:
 
  • Like
Likes BvU, sysprog and anorlunda
  • #5
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
Well, your machine will be executing machine instructions, when probably some interpreter is parsing your Python -- I think that you already know that some of the PF members, e.g. @jedishrfu and @Mark44, could be go-to guys for you if you decide to look for some assistance -- I'll try to pitch in if I think that I might be able to say something worthwhile ##\dots##
 
  • #6
That's great Greg! Don't forget to wipe down the box and packaging before touching it as there have been some COVID related isolated instances of Amazon employee protests.

Getting Started with Raspberry PI by Richardson and Wallace (OReilly pub)

Raspberry Pi in Easy Steps (full color) by McGrath

Both are newbie books but sometimes you can find what you need clearly explained.

First you'll have to choose an OS:

https://raspberrytips.com/best-os-for-raspberry-pi/

I have mine configured with Raspbian. It helps to know Python and Linux for any Raspberry PI work although you can also use C.

https://stackoverflow.com/questions/39371772/how-to-install-anaconda-on-raspberry-pi-3-model-b

I've heard that Processing can be run to Raspberry PI but while I like using it I've not installed it yet (I think you need Java and Processing and perhaps some other stuff).

https://pi.processing.org/get-started/

I've also heard that the Anaconda 3 distribution of python can be installed. Anaconda comes with a ton of python modules for doing data science and machine learning... I've installed it on my regular computers and have used the Flask api to created a simple web service.

Lastly, Pycharm is the goto IDE for python development, Jetbrains has a writeup on how to use it to do remote debug on a Pi:

https://www.jetbrains.com/help/pycharm/remote-development-on-raspberry-pi.html
 
  • Like
Likes QuantumQuest, BvU, sysprog and 1 other person
  • #7
I also use Raspbian for my Pi.

And here is a GitHub website uptime project you can take a look at, but you could just use standard Linux commands in a shell to do this, Python is considerable overkill unless you are planning to maintain tracking statistics (and even then, shell can probably do the job) 🤔
 
  • Like
Likes pbuk and sysprog
  • #8
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
 
  • Like
Likes sysprog
  • #9
Greg Bernhardt said:
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
Yup, been there, done that. o0)

Did you order a case for it already? It's good to put it into its plastic case to protect it. Also, did it come with a micro-SD card, or do you already have some? The Pi's we order don't come with one, so we've ordered a bunch for our lab stock.

https://www.raspberrypi.org/documentation/installation/sd-cards.md
 
  • Like
Likes sysprog
  • #10
LOL, I always buy a batch - Pi, power supply, SD card (micro these days, but the old Pi used the standard ones).
 
  • Like
Likes sysprog
  • #11
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)
An excellent use of time - but be careful, this is addictive!
Greg Bernhardt said:
Anyone have some "must read" tutorials? I'll be using python.
https://www.raspberrypi.org/documentation/usage/python/ - by the second page of that you'll have the LED lit up!
fresh_42 said:
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
Raspbian (the Pi-specific flavour of Linux that is best for use on the Pi) will automatically use NTP to synchronise system time with a server as soon as you give it an internet connection.
Greg Bernhardt said:
Won't do anything "real-time". Just a simple ping every second.
But you will want to write a log of down times in the next version, so will need a synchronised clock.
jedishrfu said:
First you'll have to choose an OS:
Just go with Raspbian until you find a reason not to (and unless you like getting down and dirty at the OS level, like @jedishrfu @sysprog and of course me, you won't find a reason :smile: ).
jedishrfu said:
I've also heard that the Anaconda 3 distribution of python can be installed. Anaconda comes with a ton of python modules for doing data science and machine learning... I've installed it on my regular computers and have used the Flask api to created a simple web service.
I'd only recommend this if your tutorial uses Anaconda, or more specifically conda for package management. Most Pi tutorials don't (they use pip): there is a version of Anaconda called Miniconda but it is a bit of a niche.
jedishrfu said:
Lastly, Pycharm is the goto IDE for python development, Jetbrains has a writeup on how to use it to do remote debug on a Pi:
PyCharm is great but again it is a bit of a niche on the Pi so again I'd just go with whatever your tutorial uses - the official Rasperry Pi Foundation one I linked at the top uses Thonny.
Tghu Verd said:
And here is a GitHub website uptime project you can take a look at, but you could just use standard Linux commands in a shell to do this, Python is considerable overkill unless you are planning to maintain tracking statistics (and even then, shell can probably do the job) 🤔
But shell is a dead end, and working out how to work the LED display (will this be a 7-segment display, or perhaps a 128x64 OLED?) would be a pain. There is no reason NOT to use Python which will both make the basic task much easier and also enable unlimited future development.
Greg Bernhardt said:
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
Whoops indeed - hope Amazon is still pretty quick where you are. Also is it a Pi specific breadboard kit you have got - if not then one of these to connect to the Pi's GPIO connector is much better than hooking up individual wires:

1586471725321.png

https://www.amazon.com/dp/B01N562X2P/?tag=pfamazon01-20

Enjoy!

PS I use Node on my Pis rather than Python but there is 100x more Python stuff around for the Pi, it is what it was designed for so I'd recommend you go with that unless you specifically want to learn Node.
 
  • Like
Likes QuantumQuest, Borek, chemisttree and 4 others
  • #12
Wow that was a great post @pbuk.
 
  • Like
Likes pbuk, Greg Bernhardt and berkeman
  • #13
Borek said:
At the moment I have five Pi running (I think 2, 2, 3, 0, 0, not entirely sure about exact models).
...
I am not saying these are all I have :wink:
Wow, that's an even worse habit than mine! Although I also have rather a lot of microcontrollers...
 
  • Like
Likes Borek and sysprog
  • #14
I just moved, so I am not getting into any Pi projects right now. I was planning on building a Pi cluster at one point in time, just for giggles to start playing around with parallel programming since my old job was to extend a code to distributed memory processing.
 
  • Like
Likes BvU
  • #15
Wow finally got everything I needed delivered. Got it setup and booting into NOOBS now.
 
  • Like
Likes berkeman
  • #17
Very cool, Greg! I especially like that you color coded the wiring to the Red and Green LEDs. Nice touch. :smile:
 
  • Like
Likes Greg Bernhardt
  • #18
I got the LCD to flash a message too. I'll have an update video later. This is really basic, but super fun. I just need a course in circuits 101 to advance :)
 
  • #20
Three annoyances.

1. Some LEDs dimly light up even if their state is powered off.
2. The right half of my breadboard is busted, nothing on the right gets powered. The GPIO extension board is fine though.
3. Having issues getting the script to write to a cvs file. Works fine in console, but in Cron, it won't write and no errors. Files and folders are all 777. I'm stuck.
Python:
#!/usr/bin/python3

from gpiozero import LED #for breadboard
from datetime import date #get today's date
from datetime import datetime #get today's date
import lcddriver #for lcd screen
import requests #for header info
import time #for time delay
import csv #for record keeping

#register lcd driver function
display = lcddriver.lcd()

# start up time function
def uptime(url,name,gLED_num,rLED_num,bLED_num):

    #check url header
    response = requests.get(url)
    status_code = "Status Code: " + str(response.status_code)

    #define LED colors and locations
    greenLED = LED(gLED_num)
    redLED = LED(rLED_num)
    blueLED = LED(bLED_num)

    #if server responds with header 200 light up green LED and display message on LCD
    if response.status_code == 200:
        gettime = round(response.elapsed.total_seconds(),2)
        display.lcd_display_string(name + " Speed:" + str(gettime), 1)
        display.lcd_display_string(status_code, 2)
        for x in range(0,5):
            greenLED.on()
            time.sleep(0.1)
            greenLED.off()
            time.sleep(0.1)
            if gettime > 1:
                blueLED.on()
                time.sleep(0.1)
                blueLED.off()
                time.sleep(0.1)
              
    #if not 200 then light up red LED and display message on LCD
    else:
        display.lcd_display_string(name + " is Down", 1)
        display.lcd_display_string(status_code, 2)
        for x in range(0,5):
            redLED.on()
            time.sleep(0.1)
            redLED.off()
            time.sleep(0.1)
  
    #Leave on LCD do I can have time to read
    time.sleep(1)
  
    #cleanup
    display.lcd_clear()
    greenLED.off()
    redLED.off()
    blueLED.off()
  
    # write to CSV for historical usage
    now = datetime.now()
    today = date.today()
    getnow = now.strftime('%H:%M')
    getdate = today.strftime('%m/%d/%Y')
    with open("uptime_" + name + ".csv", "a") as uptime_file:
        uptime_writer = csv.writer(uptime_file, delimiter=",",quotechar="'", quoting=csv.QUOTE_MINIMAL)
        uptime_writer.writerow([getdate,getnow,name,response.status_code,gettime])
      
    #debug
    #print(str(getdate) + " " + str(getnow) + " " + name + " " + str(response.status_code) + " " + str(gettime))

#site1 Monitor URL,greenLED,redLED,blueLED WORKS
uptime("https://www.site1.com/","site1",18,23,17)

#site2 Monitor URL,greenLED,redLED,blueLED
uptime("https://www.site2.com/","site2",27,25,5)

#site3 Mon itor URL,greenLED,redLED,blueLED
uptime("https://www.site3.com/","site3",20,16,26)

#site4 Monitor URL,greenLED,redLED,blueLED WORKS
uptime("https://www.site4.com/","site4",21,12,24)
 
Last edited:
  • #22
Greg Bernhardt said:
oh derp, the file was relative, changed to absolute and it works!

That's what I was about to suggest :)
 
  • Like
Likes Greg Bernhardt
  • #23
Greg Bernhardt said:
1. Some LEDs dimly light up even if their state is powered off.
Could be a problem with your breadboard shorting, or it could be that some other process is reconfiguring the pins as input pins when your script isn't running (I assume you mean the LEDs are dimly on while the script is not running between cron hits?)

Greg Bernhardt said:
2. The right half of my breadboard is busted, nothing on the right gets powered. The GPIO extension board is fine though.
The quality of this kind of stuff is variable, not surprising as it is ridiculously cheap. I have found Elegoo to be more reliable than others.

Greg Bernhardt said:
3. Having issues getting the script to write to a cvs file. Works fine in console, but in Cron, it won't write and no errors. Files and folders are all 777. I'm stuck.
Already solved and perhaps it's nitpicking but you should never need to use 777 permissions; your Python code runs as you so 644 (files)/755(directories) is plenty.
 
  • Like
Likes Greg Bernhardt

1. What is a Raspberry Pi 4 Website Up-Time Monitor?

A Raspberry Pi 4 Website Up-Time Monitor is a small computer that is used to monitor the up-time of a website. It collects data on how often a website is accessible and displays it in a user-friendly interface.

2. How does a Raspberry Pi 4 Website Up-Time Monitor work?

The Raspberry Pi 4 Website Up-Time Monitor uses a software program to periodically ping a website and record the response time. It then calculates the percentage of time the website is accessible and displays it on a dashboard.

3. What are the benefits of using a Raspberry Pi 4 Website Up-Time Monitor?

There are several benefits to using a Raspberry Pi 4 Website Up-Time Monitor. It helps website owners track the performance of their site, identify potential issues, and ensure maximum up-time for their visitors. It can also provide valuable data for troubleshooting and improving website performance.

4. Can a Raspberry Pi 4 Website Up-Time Monitor be used for multiple websites?

Yes, a Raspberry Pi 4 Website Up-Time Monitor can be used to monitor multiple websites. It can be configured to track the up-time of multiple websites and display the data separately for each site.

5. Is a Raspberry Pi 4 Website Up-Time Monitor easy to set up?

Yes, a Raspberry Pi 4 Website Up-Time Monitor is relatively easy to set up. It requires some basic knowledge of Raspberry Pi and coding, but there are many tutorials and guides available online to help with the setup process.

Similar threads

  • DIY Projects
Replies
4
Views
3K
Replies
3
Views
2K
  • DIY Projects
Replies
5
Views
2K
Replies
3
Views
1K
  • Programming and Computer Science
Replies
23
Views
4K
  • Computing and Technology
2
Replies
35
Views
3K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
Replies
5
Views
1K
Replies
13
Views
2K
  • Math Guides, Tutorials and Articles
Replies
8
Views
20K
Back
Top