This Python script monitors the availability of one or more websites by periodically checking their health endpoints. It writes the availability status to an InfluxDB database for further analysis and visualization.
- Checks the availability of one or more websites at regular intervals.
- Configurable number of retries before considering a check as failed.
- Verifies internet connectivity before initiating website health checks.
- Writes website availability status to an InfluxDB database.
- Visual Studio Code with the Remote - Containers extension installed.
- Docker installed on your system.
- Clone this repository.
- Open the project in Visual Studio Code.
- Build Docker Image using the provided
Dockerfile
:docker build -t website-availability-monitor .
- Copy the
example.env
file to a.env
the relevant environment variables - your InfluxDB connection parameters and the websites you want to monitor. - Run the Docker container:
docker run --env-file .env website-availability-monitor
-
Clone this repository
-
Open the project in Visual Studio Code.
-
When prompted, reopen the project in a container using the provided
.devcontainer
configuration. -
Install required Python packages by running the following command in the terminal:
pip install -r requirements.txt
-
Copy the
example.env
file to a.env
the relevant environment variables - your InfluxDB connection parameters and the websites you want to monitor. -
Launch the debugger by selecting the adequate configuration. It will load the environment variables from the
.env
file and start the script.
All the required configuration is done through the definition of environment variables, which can be consulted in example.env
.
The data written into InfluxDB is structured as follows:
The measurement name is website_status.
- website: The name of the website being monitored.
- success: A boolean value (represented as an integer, 0 for False and 1 for True) indicating whether the website is up (1) or down (0).
- response_code: The HTTP response code received when trying to access the website.
- response_time: The time taken to receive the HTTP response from the website.
- connection_time: The time taken to establish a connection to the website.
- The timestamp (time) for each data point is the current time when the data is written to InfluxDB. The precision is set to seconds.
Under assets\
you can find a JSON file that can be imported into InfluxDB to create a dashboard that visualizes the availability of the websites being monitored.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the GNU General Public License Version 2.