• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
panphora

panphora

cronSiteMonitor

Public
Like
1
cronSiteMonitor
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
6/7/2025
README.md

Robust Site Monitor

A comprehensive cron script that monitors website availability with intelligent alerting and historical tracking.

Features

Core Monitoring

  • 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

Smart Alerting

  • 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

Historical Tracking

  • Persistent storage using Val Town blob storage
  • Tracks consecutive failure counts
  • Maintains last notification timestamps
  • Records site status history

Robust Error Handling

  • Proper timeout handling with AbortController
  • Detailed error categorization (timeouts, HTTP errors, network errors)
  • Graceful handling of storage failures

Dependencies

  • https://esm.town/v/std/email - Email notifications
  • https://esm.town/v/std/blob - Persistent storage

Configuration

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

Usage

  1. Fork this val
  2. Update SITES_TO_MONITOR array with your websites
  3. Set a cron schedule (recommended: every 5-10 minutes)
  4. The script will automatically start tracking and alerting

Site Status Detection

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

Email Notifications

Downtime Alerts

  • Subject: 🚨 X site(s) down
  • Body: Detailed breakdown including:
    • Site URL
    • HTTP status code
    • Error message
    • Response time
    • Consecutive failure count

Recovery Alerts

  • Subject: ✅ X site(s) recovered
  • Body: List of recovered sites

Combined Alerts

When both downtimes and recoveries occur, both are included in a single email.

Data Storage

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.

License

WTFPL

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.