File size: 1,399 Bytes
7cec0d4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | """Monitor HF Space health for 1 hour after deployment."""
import requests
import time
import datetime
SPACE_URL = "https://mrwabbit-catalyst-cloud.hf.space/"
CHECK_INTERVAL = 120 # seconds (every 2 minutes)
TOTAL_DURATION = 3600 # 1 hour
start = time.time()
checks = 0
failures = 0
print(f"[{datetime.datetime.now():%H:%M:%S}] Starting HF Space monitoring for 1 hour...")
print(f"URL: {SPACE_URL}")
print(f"Check interval: {CHECK_INTERVAL}s")
print("-" * 60)
while time.time() - start < TOTAL_DURATION:
checks += 1
elapsed = int(time.time() - start)
try:
r = requests.get(SPACE_URL, timeout=30)
status = r.status_code
ok = 200 <= status < 400
if ok:
print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): OK (HTTP {status})")
else:
failures += 1
print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): FAIL (HTTP {status})")
except Exception as e:
failures += 1
print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): ERROR ({e})")
time.sleep(CHECK_INTERVAL)
print("-" * 60)
print(f"Monitoring complete. {checks} checks, {failures} failures.")
if failures == 0:
print("RESULT: Space is HEALTHY - no issues detected in 1 hour.")
else:
print(f"RESULT: {failures} failures detected - investigate!")
|