https://github.com/robertdevore/wp-uptime
Uptime monitoring script to keep a watchful eye on WordPress
https://github.com/robertdevore/wp-uptime
Last synced: 6 months ago
JSON representation
Uptime monitoring script to keep a watchful eye on WordPress
- Host: GitHub
- URL: https://github.com/robertdevore/wp-uptime
- Owner: robertdevore
- License: mit
- Created: 2024-12-17T15:51:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-17T16:00:34.000Z (about 1 year ago)
- Last Synced: 2025-08-14T05:04:46.069Z (6 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WP Uptime Monitor
A Python script to monitor the uptime of multiple websites, log downtime events to a CSV file, and display real-time status in the terminal.
* * *
## Features
- Monitors a list of URLs in real-time for uptime and downtime status.
- Logs downtime events to a CSV file, including start time, end time, and total downtime duration.
- Displays real-time colored output for website status:
- **Green**: Website is up.
- **Red**: Website is down.
- **Yellow**: Monitoring the downtime recovery.
- Randomizes the user-agent header for requests to mimic real browser traffic.
- Uses multi-threading for concurrent monitoring of multiple websites.
## Requirements
- Python 3.7 or later
- Libraries:
- `requests`
- Standard Python libraries: `csv`, `random`, `threading`, `datetime`, `time`
## Installation
1. Clone the repository or download the script:
```
git clone https://github.com/robertdevore/wp-uptime.git
cd wp-uptime
```
2. Install the required Python library:
```
pip install requests
```
3. Run the script:
```
python uptime_monitor.py
```
## How It Works
1. **Monitored URLs**: The script contains a pre-defined list of websites to monitor. You can customize the `urls` list in the script:
```
urls = [
"https://automattic.com/",
"https://wordpress.com/",
...
]
```
2. **Randomized Headers**: The script uses randomized user-agent headers to simulate different devices and browsers for each request.
3. **Downtime Logging**:
- When a website goes down, the start time of the downtime is recorded.
- The script continuously checks the downed site every second until it comes back online.
- Once the site is back up, the downtime duration is logged to a CSV file in the format: `uptime_log_.csv`.
4. **CSV File**: The CSV file includes the following columns:
- **URL**: The website URL.
- **Downtime Start**: Timestamp when the website went down.
- **Downtime End**: Timestamp when the website recovered.
- **Total Downtime (s)**: Downtime duration in seconds.
- **Date**: Date of the downtime.
5. **Real-time Output**:
- Website status is displayed in the terminal with colored output.
- The script checks each site every 10-20 seconds to balance resource usage.
## Output Example
### Terminal Output:
```
Monitoring started. Press Ctrl+C to stop.
https://automattic.com/ is up at 2024-06-10 10:00:00
https://wordpress.com/ went down at 2024-06-10 10:00:15
Monitoring https://wordpress.com/ every second until it comes back up...
https://wordpress.com/ is back up at 2024-06-10 10:00:30
```
### CSV Log Example:
```
URL,Downtime Start,Downtime End,Total Downtime (s),Date
https://wordpress.com/,2024-06-10 10:00:15,2024-06-10 10:00:30,15.0,2024-06-10
```
## Customization
- **Add More Websites**: Update the `urls` list in the script.
- **Modify Request Interval**: Adjust the `random.randint(10, 20)` in the `monitor_url` function to increase or decrease the wait time between checks.
- **Adjust Timeout**: Update the `timeout=5` value in the `check_status` function to allow for slower responses.
## Known Limitations
- If too many websites are monitored, CPU or memory usage might increase. Use fewer URLs if needed.
- Requires an active internet connection to monitor websites.
* * *
## Downtime Visualization
In addition to monitoring and logging downtime, a secondary script allows you to **analyze** and **visualize downtime data**. This script generates insightful metrics and a bar chart summarizing downtime occurrences and their duration.
### Features
- **Reads CSV Data**: Processes the downtime log file generated by the monitoring script.
- **Calculates Metrics**:
- Total downtime occurrences for each URL.
- Maximum downtime duration.
- Average downtime duration.
- **Visualizes Data**:
- Displays a bar chart comparing downtime counts and maximum durations per URL.
- Saves the chart as a PNG image.
* * *
### Usage
1. Run the monitoring script to generate downtime logs in a CSV format.
2. Execute the visualization script using the command-line:
```
python downtimeAnalysis.py --csv uptime_log_YYYYMMDD_HHMMSS.csv
```
Replace `uptime_log_YYYYMMDD_HHMMSS.csv` with the actual filename of your downtime log.
3. **Output**:
- A bar chart is displayed, showing total downtime counts (bar) and maximum duration (line) for each URL.
- The chart is saved as `downtime_summary.png` in the current directory.
### Example Output
#### Terminal:
```
Processing data...
Calculating metrics: 100%|█████████████████████| 20/20 [00:02<00:00, 9.82it/s]
Plot saved as 'downtime_summary.png'
```
#### Bar Chart:
The chart displays:
- **Bars**: Total downtime occurrences for each monitored URL.
- **Line**: Maximum downtime duration (seconds) for each URL.
### Dependencies
This script requires the following Python libraries:
- `pandas`
- `matplotlib`
- `tqdm`
- `argparse`
To install dependencies, run:
```
pip install pandas matplotlib tqdm
```
### Customization
- **Save Path**: Change the default save location for the chart by modifying the `save_path` argument in the `plot_downtime_summary()` function.
* * *
## License
This project is licensed under the MIT License.
## Contributing
Contributions are welcome! To contribute:
1. Fork the repository.
2. Create a feature branch (`git checkout -b feature/feature-xyz`).
3. Commit your changes and push the branch.
4. Open a pull request.