协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
uptime-robot【开发与工程】Monitor website uptime with UptimeRobot. Use when a user asks to monitor website availability, get alerts when a site goes down, create a public status page, or set up HTTP/ping/port monitoring.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
UptimeRobot is a hosted service that checks websites, APIs and servers on a schedule and alerts you when one stops answering. Monitor types include HTTP(S), keyword, ping, port, heartbeat (cron), SSL and domain expiry, DNS, UDP and API assertions. Alerts go to email, SMS, Slack, Telegram, webhooks and more, and monitors can be published on a public status page.
The free plan covers 50 monitors at 5-minute intervals with one status page and 3 months of data (hobby and non-profit use). Paid plans (Solo, Team, Scale) shorten the interval to 60, 30 or 15 seconds, add status pages, custom domains and longer retention; check uptimerobot.com/pricing for current prices.
The current REST API is v3 (https://api.uptimerobot.com/v3, bearer token, JSON). The older v2 API (api_key in a form body, numeric type codes) still exists as a legacy API; new code should use v3.
In the dashboard open Integrations, API, and create a key. Keep it in UPTIMEROBOT_API_KEY. The free plan allows 10 API requests per minute; paid plans scale with the monitor count. Over the limit you get HTTP 429 and a Retry-After header.
// lib/uptime.ts
const BASE_URL = 'https://api.uptimerobot.com/v3'
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.UPTIMEROBOT_API_KEY}`,
}
// Find alert contact IDs first
const contacts = await (await fetch(`${BASE_URL}/user/alert-contacts`, { headers })).json()
const res = await fetch(`${BASE_URL}/monitors`, {
method: 'POST',
headers,
body: JSON.stringify({
friendlyName: 'Production API',
type: 'HTTP', // HTTP, KEYWORD, PING, PORT, HEARTBEAT, DNS, API, UDP ...
url: 'https://api.northwind.io/health',
interval: 300, // seconds; the plan sets the minimum (free = 300)
timeout: 30,
assignedAlertContacts: [{ alertContactId: contacts[0].id, threshold: 0, recurrence: 0 }],
}),
})
const monitor = await res.json() // 201 on success
Other types take the fields they need: KEYWORD adds keywordType (ALERT_EXISTS), keywordValue and keywordCaseType; PORT adds port; PING and PORT take a bare host in url; HEARTBEAT takes gracePeriod and gives you a URL your cron job must call. Threshold and recurrence are paid features (always 0 on free).
const { data, nextLink } = await (
await fetch(`${BASE_URL}/monitors?status=DOWN,LOOKS_DOWN&limit=50`, { headers })
).json()
// each item: { id, friendlyName, status, url, ... }
// status: PAUSED, STARTED, UP, LOOKS_DOWN, DOWN
Results are paginated with cursor (default 50, max 200 per page). Filters: name, url, tags, groupId. Pause, resume and delete use POST /monitors/{id}/pause, POST /monitors/{id}/start and DELETE /monitors/{id}.
Create one in the dashboard under Status Pages, or via POST /psps with a friendlyName and monitorIds (or autoAddMonitors). Custom domains need a paid plan.
Request: "Alert me by email if api.northwind.io/health stops returning 200."
Run Step 2 with the alert contact for your email address. Result: the monitor is created (HTTP 201) and shows UP after its first check; when the endpoint stops answering it turns DOWN and the assigned contact is alerted.
Request: "My backup cron should ping something so I know when it silently stops."
curl -s -X POST https://api.uptimerobot.com/v3/monitors \
-H "Authorization: Bearer $UPTIMEROBOT_API_KEY" -H "Content-Type: application/json" \
-d '{"friendlyName":"Nightly backup","type":"HEARTBEAT","interval":86400,"gracePeriod":1800}'
Take the heartbeat URL from the monitor's details in the dashboard and add a final curl to it at the end of the backup script. If no ping arrives within the interval plus grace period, the monitor goes down and alerts.
newMonitor, numeric type, api_key in the body).