cronSiteMonitor
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
A comprehensive cron script that monitors website availability with intelligent alerting and historical tracking.
- Monitors multiple websites concurrently for better performance
- 10-second timeout with proper AbortController implementation
- Detailed response time tracking
- HTTP status code monitoring
- Comprehensive error categorization
- Failure Threshold: Only alerts after 2 consecutive failures (reduces false positives)
- Notification Cooldown: 30-minute cooldown between alerts for the same site
- Recovery Notifications: Alerts when sites come back online
- Detailed Error Reports: Includes status codes, error messages, response times, and failure counts
- Persistent storage using Val Town blob storage
- Tracks consecutive failure counts
- Maintains last notification timestamps
- Records site status history
- Proper timeout handling with AbortController
- Detailed error categorization (timeouts, HTTP errors, network errors)
- Graceful handling of storage failures
https://esm.town/v/std/email
- Email notificationshttps://esm.town/v/std/blob
- Persistent storage
const TIMEOUT_MS = 10000; // 10 seconds
const FAILURE_THRESHOLD = 2; // Alert after 2 consecutive failures
const NOTIFICATION_COOLDOWN_MS = 30 * 60 * 1000; // 30 minutes between notifications
- Fork this val
- Update
SITES_TO_MONITOR
array with your websites - Set a cron schedule (recommended: every 5-10 minutes)
- The script will automatically start tracking and alerting
A site is considered "down" if:
- No response within 10 seconds (timeout)
- Returns a non-2xx HTTP status code
- Network/connection errors occur
- DNS resolution fails
- Subject:
🚨 X site(s) down
- Body: Detailed breakdown including:
- Site URL
- HTTP status code
- Error message
- Response time
- Consecutive failure count
- Subject:
✅ X site(s) recovered
- Body: List of recovered sites
When both downtimes and recoveries occur, both are included in a single email.
The script maintains persistent state in Val Town blob storage:
uptime_history
: JSON object tracking each site's status history- Includes last status, consecutive failures, last notification time, etc.
WTFPL