Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c51e12fba9 | ||
|
|
1e85a210f5 |
No files matched your search
@@ -60,7 +60,7 @@ whether the page is running or paused.
|
|||||||
|
|
||||||
The page checks 26 hosts on the internet, the WAN hosts:
|
The page checks 26 hosts on the internet, the WAN hosts:
|
||||||
|
|
||||||
- `datavi.be`, pinned to the top at start
|
- `datavi.be`, pinned to the top by default
|
||||||
- the Anthropic API and the OpenAI API
|
- the Anthropic API and the OpenAI API
|
||||||
- the AWS Console, the Google Cloud Console and Microsoft Azure
|
- the AWS Console, the Google Cloud Console and Microsoft Azure
|
||||||
- Cloudflare, Fastly, Akamai, Google, GitHub and Backblaze B2
|
- Cloudflare, Fastly, Akamai, Google, GitHub and Backblaze B2
|
||||||
@@ -130,7 +130,7 @@ top, and the figure still shows its real value.
|
|||||||
|
|
||||||
From time to time, the page sorts the WAN rows by their latest latency: fastest
|
From time to time, the page sorts the WAN rows by their latest latency: fastest
|
||||||
first, failed last. The pin button at the left of a row keeps the row at the
|
first, failed last. The pin button at the left of a row keeps the row at the
|
||||||
top; pinned rows are sorted by name. `datavi.be` is pinned at start.
|
top; pinned rows are sorted by name. `datavi.be` is pinned until you unpin it.
|
||||||
|
|
||||||
`Pause` stops the checks: the graphs keep scrolling with a gap for each paused
|
`Pause` stops the checks: the graphs keep scrolling with a gap for each paused
|
||||||
round, and the figures and dots turn gray. The `Interval` menu sets the time
|
round, and the figures and dots turn gray. The `Interval` menu sets the time
|
||||||
@@ -138,6 +138,10 @@ between rounds: 1, 2, 3, 5, 10, 15, 30 or 60 seconds. Changing it clears the
|
|||||||
history and starts a new round at once. The `Debug log` checkbox in the footer
|
history and starts a new round at once. The `Debug log` checkbox in the footer
|
||||||
opens a panel with the page's last 1000 log lines.
|
opens a panel with the page's last 1000 log lines.
|
||||||
|
|
||||||
|
The page keeps the interval and the pinned rows in the browser's `localStorage`,
|
||||||
|
so a reload starts with them. Each browser keeps its own. A browser with no
|
||||||
|
usable storage starts at 3 seconds with `datavi.be` pinned.
|
||||||
|
|
||||||
## Reporting
|
## Reporting
|
||||||
|
|
||||||
Every 60 seconds the page posts its undelivered samples as a report to
|
Every 60 seconds the page posts its undelivered samples as a report to
|
||||||
@@ -380,6 +384,8 @@ The page is built with Vite and Tailwind CSS v4. All its code is in
|
|||||||
method `HEAD`.
|
method `HEAD`.
|
||||||
- `HostState` and `AppState`: one host's history and status, and the whole
|
- `HostState` and `AppState`: one host's history and status, and the whole
|
||||||
page's state.
|
page's state.
|
||||||
|
- `savedInterval`, `savedPinnedNames`, `saveInterval` and `savePinnedNames`:
|
||||||
|
read and write the interval and the pinned WAN hosts in `localStorage`.
|
||||||
- `measureLatency`: one check. `tick`: one round, which checks every host in
|
- `measureLatency`: one check. `tick`: one round, which checks every host in
|
||||||
parallel. It draws each row as soon as its check ends, and with a WAN host's
|
parallel. It draws each row as soon as its check ends, and with a WAN host's
|
||||||
row also the summary and the health box.
|
row also the summary and the health box.
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import {
|
|||||||
log,
|
log,
|
||||||
measureLatency,
|
measureLatency,
|
||||||
Reporter,
|
Reporter,
|
||||||
|
savedInterval,
|
||||||
|
savedPinnedNames,
|
||||||
|
saveInterval,
|
||||||
|
savePinnedNames,
|
||||||
tick,
|
tick,
|
||||||
updateClocks,
|
updateClocks,
|
||||||
updateSummary,
|
updateSummary,
|
||||||
@@ -1054,3 +1058,101 @@ for (const { timedOut, unreachable = 0, answered, latency, health } of [
|
|||||||
assert.equal(state.healthStatus(), health);
|
assert.equal(state.healthStatus(), health);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gives test t a browser storage that keeps its values in saved, or, with
|
||||||
|
// saved null, one that throws on every read and write, as a browser with
|
||||||
|
// storage turned off does. It is removed when the test ends.
|
||||||
|
function mockStorage(t, saved) {
|
||||||
|
const fail = () => {
|
||||||
|
throw new Error("The operation is insecure.");
|
||||||
|
};
|
||||||
|
globalThis.localStorage =
|
||||||
|
saved === null
|
||||||
|
? { getItem: fail, setItem: fail }
|
||||||
|
: {
|
||||||
|
getItem: (key) => saved[key] ?? null,
|
||||||
|
setItem: (key, value) => {
|
||||||
|
saved[key] = value;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
t.after(() => delete globalThis.localStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The interval menu's selected option in the page buildUI draws.
|
||||||
|
function selectedInterval(t) {
|
||||||
|
const app = {};
|
||||||
|
t.mock.method(globalThis.document, "getElementById", () => app);
|
||||||
|
buildUI(new AppState([]));
|
||||||
|
return app.innerHTML.match(/<option value="(\d+)" selected>/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// The names of the pinned WAN targets in state.
|
||||||
|
function pinnedNames(state) {
|
||||||
|
return state.wan.filter((h) => h.pinned).map((h) => h.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
test("after the user sets the interval to 10s, unpins datavi.be and pins GitHub, a reload starts at 10s with only GitHub pinned", (t) => {
|
||||||
|
mockStorage(t, {});
|
||||||
|
CONFIG.updateInterval = 3000;
|
||||||
|
const before = new AppState([], savedPinnedNames());
|
||||||
|
saveInterval(10000);
|
||||||
|
for (const host of before.wan) host.pinned = host.name === "GitHub";
|
||||||
|
savePinnedNames(before);
|
||||||
|
|
||||||
|
CONFIG.updateInterval = savedInterval();
|
||||||
|
const after = new AppState([], savedPinnedNames());
|
||||||
|
|
||||||
|
assert.equal(CONFIG.updateInterval, 10000);
|
||||||
|
assert.equal(selectedInterval(t), "10000");
|
||||||
|
assert.deepEqual(pinnedNames(after), ["GitHub"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a reload with Google and GitHub pinned starts with them at the top, by name", (t) => {
|
||||||
|
mockStorage(t, { "netwatch-pinned": '["Google","GitHub"]' });
|
||||||
|
|
||||||
|
const state = new AppState([], savedPinnedNames());
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
state.wan.slice(0, 2).map((h) => h.name),
|
||||||
|
["GitHub", "Google"],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("after the user unpins every target, a reload starts with none pinned", (t) => {
|
||||||
|
mockStorage(t, {});
|
||||||
|
const before = new AppState([], savedPinnedNames());
|
||||||
|
for (const host of before.wan) host.pinned = false;
|
||||||
|
savePinnedNames(before);
|
||||||
|
|
||||||
|
const after = new AppState([], savedPinnedNames());
|
||||||
|
|
||||||
|
assert.deepEqual(pinnedNames(after), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const [browser, saved] of [
|
||||||
|
["that has saved nothing", {}],
|
||||||
|
[
|
||||||
|
"whose saved interval is not in the menu and whose saved pins are not a list of names",
|
||||||
|
{ "netwatch-interval": "7000", "netwatch-pinned": '{"GitHub":true}' },
|
||||||
|
],
|
||||||
|
["whose saved pins are not JSON", { "netwatch-pinned": "GitHub" }],
|
||||||
|
["with storage turned off", null],
|
||||||
|
]) {
|
||||||
|
test(`a browser ${browser} starts at 3s with only datavi.be pinned`, (t) => {
|
||||||
|
mockStorage(t, saved);
|
||||||
|
CONFIG.updateInterval = 3000;
|
||||||
|
|
||||||
|
CONFIG.updateInterval = savedInterval();
|
||||||
|
const state = new AppState([], savedPinnedNames());
|
||||||
|
|
||||||
|
assert.equal(CONFIG.updateInterval, 3000);
|
||||||
|
assert.equal(selectedInterval(t), "3000");
|
||||||
|
assert.deepEqual(pinnedNames(state), ["datavi.be"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("in a browser with storage turned off, changing the interval or a pin throws nothing", (t) => {
|
||||||
|
mockStorage(t, null);
|
||||||
|
saveInterval(10000);
|
||||||
|
savePinnedNames(new AppState([]));
|
||||||
|
});
|
||||||
+90
-19
@@ -65,6 +65,12 @@ export const CONFIG = {
|
|||||||
resizeDelay: 100,
|
resizeDelay: 100,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The interval menu's choices, in ms.
|
||||||
|
const INTERVAL_CHOICES = [1000, 2000, 3000, 5000, 10000, 15000, 30000, 60000];
|
||||||
|
|
||||||
|
// The WAN hosts pinned in a browser that has saved no pins.
|
||||||
|
const DEFAULT_PINNED = ["datavi.be"];
|
||||||
|
|
||||||
// WAN endpoints to monitor. These are used for the aggregate health/stats
|
// WAN endpoints to monitor. These are used for the aggregate health/stats
|
||||||
// display (min/max/avg). Ordered: personal, LLM APIs, big-3 cloud, then
|
// display (min/max/avg). Ordered: personal, LLM APIs, big-3 cloud, then
|
||||||
// CDN/hosting/other. A check follows a redirect and times the request to
|
// CDN/hosting/other. A check follows a redirect and times the request to
|
||||||
@@ -350,9 +356,12 @@ export class HostState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AppState {
|
export class AppState {
|
||||||
constructor(localHosts) {
|
// pinnedNames: the names of the WAN hosts to pin.
|
||||||
this.wan = WAN_HOSTS.map(
|
constructor(localHosts, pinnedNames = DEFAULT_PINNED) {
|
||||||
(h) => new HostState(h, h.name === "datavi.be"),
|
this.wan = sortedWAN(
|
||||||
|
WAN_HOSTS.map(
|
||||||
|
(h) => new HostState(h, pinnedNames.includes(h.name)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
this.local = localHosts.map((h) => new HostState(h));
|
this.local = localHosts.map((h) => new HostState(h));
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
@@ -422,6 +431,60 @@ export class AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Saved Settings ----------------------------------------------------------
|
||||||
|
|
||||||
|
// The interval and the names of the pinned WAN hosts are kept in
|
||||||
|
// localStorage, so each browser starts with the ones it last had. A browser
|
||||||
|
// with no usable storage, or a saved value the page cannot use, starts with
|
||||||
|
// the defaults.
|
||||||
|
const INTERVAL_KEY = "netwatch-interval";
|
||||||
|
const PINNED_KEY = "netwatch-pinned";
|
||||||
|
|
||||||
|
// The saved interval in ms, or CONFIG.updateInterval if none is saved.
|
||||||
|
export function savedInterval() {
|
||||||
|
try {
|
||||||
|
const ms = Number(localStorage.getItem(INTERVAL_KEY));
|
||||||
|
if (INTERVAL_CHOICES.includes(ms)) return ms;
|
||||||
|
} catch {
|
||||||
|
// No usable storage.
|
||||||
|
}
|
||||||
|
return CONFIG.updateInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The saved names of the pinned WAN hosts, or DEFAULT_PINNED if none are
|
||||||
|
// saved. A saved name no WAN host has pins nothing.
|
||||||
|
export function savedPinnedNames() {
|
||||||
|
try {
|
||||||
|
const names = JSON.parse(localStorage.getItem(PINNED_KEY));
|
||||||
|
if (
|
||||||
|
Array.isArray(names) &&
|
||||||
|
names.every((name) => typeof name === "string")
|
||||||
|
)
|
||||||
|
return names;
|
||||||
|
} catch {
|
||||||
|
// No usable storage, or a saved value that is not JSON.
|
||||||
|
}
|
||||||
|
return DEFAULT_PINNED;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveInterval(ms) {
|
||||||
|
saveSetting(INTERVAL_KEY, String(ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function savePinnedNames(state) {
|
||||||
|
const names = state.wan.filter((h) => h.pinned).map((h) => h.name);
|
||||||
|
saveSetting(PINNED_KEY, JSON.stringify(names));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A setting the browser cannot store lasts until the page is reloaded.
|
||||||
|
function saveSetting(key, value) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key, value);
|
||||||
|
} catch {
|
||||||
|
// No usable storage.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- Reporting ---------------------------------------------------------------
|
// --- Reporting ---------------------------------------------------------------
|
||||||
|
|
||||||
// A random UUIDv4. `crypto.randomUUID` exists only in secure contexts
|
// A random UUIDv4. `crypto.randomUUID` exists only in secure contexts
|
||||||
@@ -848,6 +911,14 @@ function wanRowsHTML(wanHosts) {
|
|||||||
return rows.join("");
|
return rows.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The interval menu's options, with CONFIG.updateInterval selected.
|
||||||
|
function intervalOptionsHTML() {
|
||||||
|
return INTERVAL_CHOICES.map((ms) => {
|
||||||
|
const selected = ms === CONFIG.updateInterval ? " selected" : "";
|
||||||
|
return `<option value="${ms}"${selected}>${ms / 1000}s</option>`;
|
||||||
|
}).join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
export function buildUI(state) {
|
export function buildUI(state) {
|
||||||
const app = document.getElementById("app");
|
const app = document.getElementById("app");
|
||||||
app.innerHTML = `
|
app.innerHTML = `
|
||||||
@@ -869,14 +940,7 @@ export function buildUI(state) {
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<label class="text-gray-400 text-sm">Interval:</label>
|
<label class="text-gray-400 text-sm">Interval:</label>
|
||||||
<select id="interval-select" class="bg-gray-800 border border-gray-600 text-white text-sm rounded-lg px-2 py-1 focus:outline-none focus:ring-2 focus:ring-blue-500 cursor-pointer">
|
<select id="interval-select" class="bg-gray-800 border border-gray-600 text-white text-sm rounded-lg px-2 py-1 focus:outline-none focus:ring-2 focus:ring-blue-500 cursor-pointer">
|
||||||
<option value="1000">1s</option>
|
${intervalOptionsHTML()}
|
||||||
<option value="2000">2s</option>
|
|
||||||
<option value="3000" selected>3s</option>
|
|
||||||
<option value="5000">5s</option>
|
|
||||||
<option value="10000">10s</option>
|
|
||||||
<option value="15000">15s</option>
|
|
||||||
<option value="30000">30s</option>
|
|
||||||
<option value="60000">60s</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1207,21 +1271,25 @@ function appendDebugLogLine(entry) {
|
|||||||
|
|
||||||
// --- Sorting -----------------------------------------------------------------
|
// --- Sorting -----------------------------------------------------------------
|
||||||
|
|
||||||
// Sort WAN hosts: pinned hosts first (alphabetically), then unpinned hosts
|
// The WAN hosts sorted: pinned hosts first (alphabetically), then unpinned
|
||||||
// by last latency ascending, with unreachable hosts at the bottom.
|
// hosts by last latency ascending, with unreachable hosts at the bottom.
|
||||||
function sortAndRebuildWAN(state) {
|
function sortedWAN(hosts) {
|
||||||
log.debug("WAN hosts re-sorted");
|
const pinned = hosts
|
||||||
const pinned = state.wan
|
|
||||||
.filter((h) => h.pinned)
|
.filter((h) => h.pinned)
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
const rest = state.wan.filter((h) => !h.pinned);
|
const rest = hosts.filter((h) => !h.pinned);
|
||||||
rest.sort((a, b) => {
|
rest.sort((a, b) => {
|
||||||
if (a.lastLatency === null && b.lastLatency === null) return 0;
|
if (a.lastLatency === null && b.lastLatency === null) return 0;
|
||||||
if (a.lastLatency === null) return 1;
|
if (a.lastLatency === null) return 1;
|
||||||
if (b.lastLatency === null) return -1;
|
if (b.lastLatency === null) return -1;
|
||||||
return a.lastLatency - b.lastLatency;
|
return a.lastLatency - b.lastLatency;
|
||||||
});
|
});
|
||||||
state.wan = [...pinned, ...rest];
|
return [...pinned, ...rest];
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortAndRebuildWAN(state) {
|
||||||
|
log.debug("WAN hosts re-sorted");
|
||||||
|
state.wan = sortedWAN(state.wan);
|
||||||
|
|
||||||
const container = document.getElementById("wan-hosts");
|
const container = document.getElementById("wan-hosts");
|
||||||
container.innerHTML = wanRowsHTML(state.wan);
|
container.innerHTML = wanRowsHTML(state.wan);
|
||||||
@@ -1520,7 +1588,8 @@ async function init() {
|
|||||||
log.info(`Gateway detected: ${gateway.url}`);
|
log.info(`Gateway detected: ${gateway.url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = new AppState(localHosts);
|
CONFIG.updateInterval = savedInterval();
|
||||||
|
const state = new AppState(localHosts, savedPinnedNames());
|
||||||
buildUI(state);
|
buildUI(state);
|
||||||
log.info("UI built, starting tick loop");
|
log.info("UI built, starting tick loop");
|
||||||
|
|
||||||
@@ -1560,6 +1629,7 @@ async function init() {
|
|||||||
if (!host) return;
|
if (!host) return;
|
||||||
host.pinned = !host.pinned;
|
host.pinned = !host.pinned;
|
||||||
log.notice(`${host.pinned ? "Pinned" : "Unpinned"} ${host.name}`);
|
log.notice(`${host.pinned ? "Pinned" : "Unpinned"} ${host.name}`);
|
||||||
|
savePinnedNames(state);
|
||||||
sortAndRebuildWAN(state);
|
sortAndRebuildWAN(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1592,6 +1662,7 @@ async function init() {
|
|||||||
.addEventListener("change", (e) => {
|
.addEventListener("change", (e) => {
|
||||||
const newInterval = parseInt(e.target.value, 10);
|
const newInterval = parseInt(e.target.value, 10);
|
||||||
CONFIG.updateInterval = newInterval;
|
CONFIG.updateInterval = newInterval;
|
||||||
|
saveInterval(newInterval);
|
||||||
log.notice(
|
log.notice(
|
||||||
`Interval changed to ${humanDuration(newInterval / 1000)}, history reset`,
|
`Interval changed to ${humanDuration(newInterval / 1000)}, history reset`,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user