Readme

Uptime Checker & Status Page

This val is a free uptime/downtime checker that sends you an email when the site doesn't return a 200. It also stores historical uptime and latency data in your Val Town SQLite, which is used to power a status page. It supports multiple URLs in the same database and status page.

Installation

  1. Fork this val
  2. Edit the list of URLs to what you want to check
  3. For the status page, fork this val: @stevekrouse/status
Runs every 15 min
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import { email } from "https://esm.town/v/std/email?v=11";
import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
await sqlite.execute(
"CREATE TABLE IF NOT EXISTS uptime (id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT, ok INTEGER, reason TEXT, status INTEGER, duration INTEGER, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP);",
);
export async function uptimeCheck(url: string) {
let ok = true;
let reason: string;
let status: number;
let start: number;
let end: number;
start = performance.now();
try {
const res = await fetch(url);
end = performance.now();
status = res.status;
if (res.status === 200) {
console.log(`Website up (${url}): ${res.status} (${end - start}ms)`);
} else {
ok = false;
console.log(`Website down (${url}): ${res.status} (${end - start}ms)`);
}
} catch (e) {
end = performance.now();
reason = `couldn't fetch: ${e}`;
ok = false;
console.log(`Website down (${url}): ${reason} (${end - start}ms)`);
}
if (!ok) {
email({ subject: `Website down (${url})` });
}
if (url.includes("jonnie.com")) {
await sqlite.execute(
{
sql: "DELETE FROM uptime WHERE url = ?",
args: [url],
},
);
return;
}
await sqlite.execute(
{
sql: "INSERT INTO uptime (url, ok, reason, status, duration) VALUES (?, ?, ?, ?, ?)",
args: [url, ok ? 1 : 0, reason, status, end - start],
},
);
}
export default async () => {
["https://faith.tools/", "https://melos.church", "https://cameronpak.com"].forEach(uptimeCheck);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 11, 2024