Skip to content

Commit 85d01b7

Browse files
feat: add website uptime monitor
1 parent 440331f commit 85d01b7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

site_monitor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import requests, time, smtplib
2+
from datetime import datetime
3+
4+
SITES = [
5+
"https://www.google.com",
6+
"https://github.com",
7+
]
8+
CHECK_INTERVAL = 60
9+
10+
def check(url):
11+
try:
12+
r = requests.get(url, timeout=10)
13+
return r.status_code < 400
14+
except Exception:
15+
return False
16+
17+
def monitor():
18+
print(f"Monitoring {len(SITES)} sites every {CHECK_INTERVAL}s...")
19+
while True:
20+
for url in SITES:
21+
status = "UP" if check(url) else "DOWN"
22+
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
23+
print(f"[{ts}] {url}: {status}")
24+
time.sleep(CHECK_INTERVAL)
25+
26+
if __name__ == "__main__":
27+
monitor()

0 commit comments

Comments
 (0)