diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/demo.yml
similarity index 54%
rename from .github/workflows/jekyll-gh-pages.yml
rename to .github/workflows/demo.yml
index 6454f84..79f4ead 100644
--- a/.github/workflows/jekyll-gh-pages.yml
+++ b/.github/workflows/demo.yml
@@ -1,28 +1,24 @@
-# Sample workflow for building and deploying a Jekyll site to GitHub Pages
-name: Deploy Jekyll with GitHub Pages dependencies preinstalled
+# Publishes the static demo of the web UI (scripts/demo) to GitHub Pages:
+# https://githubflyideas.github.io/fogping/
+# Once: Settings > Pages > Build and deployment > Source: GitHub Actions.
+name: demo
on:
- # Runs on pushes targeting the default branch
push:
branches: ["main"]
-
- # Allows you to run this workflow manually from the Actions tab
+ paths: ["static/**", "scripts/demo/**", ".github/workflows/demo.yml"]
workflow_dispatch:
-# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
-# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
-# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
- # Build job
build:
runs-on: ubuntu-latest
steps:
@@ -30,15 +26,13 @@ jobs:
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- name: Setup Pages
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
- - name: Build with Jekyll
- uses: actions/jekyll-build-pages@44a6e6beabd48582f863aeeb6cb2151cc1716697 # v1.0.13
- with:
- source: ./
- destination: ./_site
+ - name: Build the demo
+ run: scripts/demo/build.sh dist-demo
- name: Upload artifact
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
+ with:
+ path: dist-demo
- # Deployment job
deploy:
environment:
name: github-pages
diff --git a/.gitignore b/.gitignore
index 4e7f29a..98aea5f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
*.db
*.db-wal
*.db-shm
+dist-demo/
diff --git a/README.md b/README.md
index f603058..94f0bef 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,8 @@
>
> *🚫 No Perl. No RRDtool. No Web Server. No Config Files.*
+**▶ [Try the live demo (read-only, simulated data)](https://githubflyideas.github.io/fogping/)**
+
diff --git a/index.html b/index.html
deleted file mode 100644
index 1ed0f49..0000000
--- a/index.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/scripts/demo/build.sh b/scripts/demo/build.sh
new file mode 100755
index 0000000..714f8a4
--- /dev/null
+++ b/scripts/demo/build.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Builds the static demo of the web UI into $1 (default dist-demo): the page
+# as shipped, plus demo.js, which answers the page's /api/ requests in the
+# browser from simulated links. Serve the directory as plain files (GitHub Pages).
+set -e
+here=$(cd "$(dirname "$0")" && pwd)
+root=$(cd "$here/../.." && pwd)
+out=${1:-$root/dist-demo}
+rm -rf "$out"; mkdir -p "$out/static" "$out/demo"
+cp "$root/static/echarts.min.js" "$out/static/"
+cp "$here/demo.js" "$out/demo/demo.js"
+# The site lives under /fogping/, so the page's one absolute asset path becomes
+# relative; demo.js loads before the page's own script, and a ribbon says what
+# this is.
+sed -e 's#src="/static/echarts.min.js"#src="static/echarts.min.js"#' \
+ -e 's##\n\n#' \
+ "$root/static/index.html" > "$out/index.html"
+grep -q 'src="static/echarts.min.js"' "$out/index.html" || { echo "build.sh: echarts path not found in static/index.html" >&2; exit 1; }
+grep -q 'demo/demo.js' "$out/index.html" || { echo "build.sh: not found in static/index.html" >&2; exit 1; }
+touch "$out/.nojekyll"
+echo "demo built in $out"
diff --git a/scripts/demo/demo.js b/scripts/demo/demo.js
new file mode 100644
index 0000000..3502bd5
--- /dev/null
+++ b/scripts/demo/demo.js
@@ -0,0 +1,242 @@
+// The static demo of fogping: the web UI as shipped, served without a server.
+// Every /api/ request the page makes is answered here, in the browser, from a
+// model of a few links (see TARGETS). The model is a pure function of the target
+// and the clock, so a round looks the same on every visit and every refresh, new
+// rounds keep arriving, and "yesterday" and "last week" exist for COMPARE.
+// Nothing is saved: a change is answered with a notice.
+// Loaded before the page's own script (see build.sh); not part of the product.
+(() => {
+ 'use strict';
+ const DAY = 86400, HOUR = 3600;
+ const RETENTION_DAYS = 93, HOT_DAYS = 2;
+ const LOAD = Math.floor(Date.now() / 1000); // the demo's "now" for events tied to the visit
+ const TZ = 9 * HOUR; // the links below live in Japan: evenings are JST evenings
+
+ // ---- deterministic noise -------------------------------------------------
+ const strHash = s => { let h = 2166136261; for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619); return h >>> 0; };
+ const mix = (a, b) => { let h = Math.imul(a ^ (b + 0x9e3779b9 + (a << 6) + (a >>> 2)), 0x85ebca6b); h ^= h >>> 13; h = Math.imul(h, 0xc2b2ae35); return (h ^ (h >>> 16)) >>> 0; };
+ function rng(seed) { // mulberry32
+ let a = seed >>> 0;
+ return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
+ }
+ const gauss = r => { let u = 0; while (!u) u = r(); return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * r()); };
+ const r2 = v => Math.round(v * 100) / 100;
+
+ // ---- the links -----------------------------------------------------------
+ // base: quiet-hour RTT (ms); jit: spread of a round's samples; eve: how much
+ // the evening peak lifts and widens the smoke; loss: background loss per packet;
+ // ev: chance per hour of a congestion event (latency climbs, packets drop, ◆).
+ const TARGETS = [
+ { id: 1, name: 'Tokyo IX', type: 'ping', host: 'ix-tky.example.net', pace: 'fast', base: 17, jit: 1.6, eve: 1.4, loss: 0.0006, ev: 0.14,
+ shift: { at: -3 * DAY - 5 * HOUR, len: 7 * HOUR, by: 9 }, // a reroute three days ago: +9 ms for seven hours
+ incident: { start: LOAD - 75 * 60, len: 12 * 60, depth: 0.8 } }, // so the first chart a visitor sees has a burst ◆
+ { id: 2, name: 'Cloudflare DNS', type: 'ping', host: '1.1.1.1', pace: 'fast', base: 4.2, jit: 0.35, eve: 0.25, loss: 0.0002, ev: 0.02 },
+ { id: 3, name: 'Google DNS', type: 'ping', host: '8.8.8.8', pace: 'normal', base: 8.6, jit: 0.7, eve: 0.35, loss: 0.0003, ev: 0.03 },
+ { id: 4, name: 'Home gateway', type: 'ping', host: '192.168.1.1', pace: 'fast', base: 0.9, jit: 0.25, eve: 0.1, loss: 0, ev: 0.01 },
+ { id: 5, name: 'AWS us-west-2', type: 'tcp', host: 'ec2.us-west-2.amazonaws.com', port: 443, pace: 'normal', base: 104, jit: 3.5, eve: 0.5, loss: 0.001, ev: 0.05 },
+ { id: 6, name: 'Frankfurt edge', type: 'tcp', host: 'fra.edge.example.com', port: 443, pace: 'normal', base: 231, jit: 9, eve: 0.9, loss: 0.002, ev: 0.08 },
+ { id: 7, name: 'Shop website', type: 'http', host: 'shop.example.com', port: 443, pace: 'normal', base: 82, jit: 14, eve: 0.7, loss: 0.0008, ev: 0.04,
+ options: { scheme: 'https', method: 'GET', path: '/health', expect_status: 200 } },
+ { id: 8, name: 'Branch VPN', type: 'ping', host: '10.8.0.1', pace: 'fast', base: 28, jit: 2.2, eve: 1.1, loss: 0.0012, ev: 0.07,
+ down: { from: LOAD - 22 * 60 } }, // went dark 22 minutes before the visit: red LED, red bars at the right edge
+ { id: 9, name: 'NAS', type: 'tcp', host: 'nas.lan', port: 445, pace: 'slow', base: 1.4, jit: 0.3, eve: 0.1, loss: 0, ev: 0,
+ dnsFail: { from: LOAD - 40 * 60, error: 'lookup nas.lan: no such host' } }, // could not be measured: amber LED, not loss
+ ];
+ const PACE = { fast: [15, 30], normal: [60, 20], slow: [300, 20] }; // interval s, packets per round
+ for (const t of TARGETS) {
+ t.seed = strHash(t.name);
+ [t.interval, t.packets] = PACE[t.pace];
+ t.addr = t.port ? `${t.host}:${t.port}` : t.host;
+ }
+ const byName = n => TARGETS.find(t => t.name === n);
+
+ // ---- the model -----------------------------------------------------------
+ // Evening load, 0..1: rises from 18:00, peaks around 21:30, gone by 01:00;
+ // a smaller lunchtime bump; weekends a little busier in the afternoon.
+ function load(t) {
+ const local = t + TZ, h = ((local % DAY) + DAY) % DAY / HOUR;
+ const dow = Math.floor(local / DAY + 4) % 7; // 0 = Sunday
+ const bell = (c, w) => Math.exp(-((h - c) ** 2) / (2 * w * w));
+ let l = bell(21.5, 1.8) + 0.25 * bell(12.5, 1);
+ if (dow === 0 || dow === 6) l += 0.3 * bell(15, 2.5);
+ return Math.min(1, l);
+ }
+ // A congestion event in hour H, if any: { start, len, depth } (seconds, 0..1).
+ function eventIn(tg, H) {
+ const r = rng(mix(tg.seed, H * 7 + 1));
+ const p = tg.ev * (0.4 + 1.6 * load(H * HOUR + HOUR / 2));
+ if (r() >= p) return null;
+ return { start: H * HOUR + Math.floor(r() * 50) * 60, len: (4 + Math.floor(r() * 18)) * 60, depth: 0.3 + 0.7 * r() };
+ }
+ function eventAt(tg, t) {
+ const H = Math.floor(t / HOUR);
+ for (const h of [H, H - 1, null]) {
+ const e = h === null ? tg.incident : eventIn(tg, h);
+ if (e && t >= e.start && t < e.start + e.len) {
+ const x = (t - e.start) / e.len; // 0..1 through the event: a hump
+ return e.depth * Math.sin(Math.PI * x);
+ }
+ }
+ return 0;
+ }
+ // One round at time t (aligned to the target's interval).
+ function round(tg, t) {
+ const k = Math.floor(t / tg.interval);
+ const r = rng(mix(tg.seed, k));
+ if (tg.dnsFail && t >= tg.dnsFail.from) return { t, s: 0, r: 0, ms: [], e: tg.dnsFail.error };
+ const s = tg.packets;
+ if (tg.down && t >= tg.down.from) return { t, s, r: 0, ms: [], b: t < tg.down.from + 2 * tg.interval, z: 9.6 };
+ const l = load(t), ev = eventAt(tg, t);
+ let base = tg.base * (1 + 0.06 * l) + (tg.base * 0.9 + 6) * ev;
+ if (tg.shift && t - LOAD >= tg.shift.at && t - LOAD < tg.shift.at + tg.shift.len) base += tg.shift.by;
+ base *= 1 + 0.015 * Math.sin(t / 5400 + tg.seed); // slow wander
+ const spread = tg.jit * (1 + tg.eve * l + 3 * ev);
+ const pLoss = tg.loss * (1 + 3 * l) + 0.55 * ev ** 1.5;
+ const ms = [];
+ for (let i = 0; i < s; i++) {
+ if (r() < pLoss) continue;
+ let v = base + Math.abs(gauss(r)) * spread * 0.8 + gauss(r) * spread * 0.25;
+ if (r() < 0.015 + 0.05 * ev) v += spread * (2 + 6 * r()); // the odd straggler
+ ms.push(r2(Math.max(tg.base * 0.9, v)));
+ }
+ const lost = s - ms.length, lp = lost / s;
+ const out = { t, s, r: ms.length, ms };
+ if (lp >= 0.15) { out.b = true; out.z = r2(3.5 + 12 * lp + r()); }
+ else if (lost) out.z = r2(0.6 + 4 * lp);
+ return out;
+ }
+ function rawRounds(tg, from, to) {
+ const out = [];
+ for (let t = Math.ceil(from / tg.interval) * tg.interval; t <= to; t += tg.interval) out.push(round(tg, t));
+ return out;
+ }
+ const quant = (srt, p) => srt[Math.min(srt.length - 1, Math.floor(srt.length * p))];
+ // An hourly bucket, rolled up from a sample of the hour's rounds (every 5 min).
+ function bucket(tg, H) {
+ const t0 = H * HOUR, all = [];
+ let sent = 0, recv = 0, bursts = 0, n = 0, measured = 0;
+ for (let t = t0; t < t0 + HOUR; t += 300) {
+ const rd = round(tg, Math.floor(t / tg.interval) * tg.interval);
+ n++;
+ if (!rd.s) continue;
+ measured++; sent += rd.s; recv += rd.r; if (rd.b) bursts++;
+ all.push(...rd.ms);
+ }
+ const b = { t: t0, loss: sent ? r2((sent - recv) / sent * 100) : 0, n: Math.round(n * 300 / tg.interval) };
+ if (bursts) b.bursts = Math.round(bursts * 300 / tg.interval);
+ if (all.length) { all.sort((a, b) => a - b); b.q = [all[0], quant(all, .5), quant(all, .9), quant(all, .99), all[all.length - 1]].map(r2); }
+ return measured ? b : null;
+ }
+ function series(tg, from, to) {
+ const floor = Math.floor(Date.now() / 1000) - RETENTION_DAYS * DAY;
+ from = Math.max(from, floor);
+ if (to <= from) return { tier: 'raw' };
+ if (to - from <= DAY) return { tier: 'raw', rounds: rawRounds(tg, from, to) };
+ const buckets = [];
+ for (let H = Math.floor(from / HOUR); H * HOUR <= to; H++) { const b = bucket(tg, H); if (b) buckets.push(b); }
+ return { tier: 'hourly', buckets };
+ }
+ function stats(rounds) {
+ const pool = []; let sent = 0, recv = 0, n = 0, bursts = 0, errs = 0;
+ for (const r of rounds) {
+ if (!r.s) { errs++; continue; }
+ n++; sent += r.s; recv += r.r; if (r.b) bursts++; pool.push(...r.ms);
+ }
+ pool.sort((a, b) => a - b);
+ const q = p => pool.length ? r2(quant(pool, p)) : 0;
+ return { rounds: n, p50: q(.5), p90: q(.9), p99: q(.99), loss_pct: sent ? r2((sent - recv) / sent * 100) : 0, bursts, probe_errors: errs };
+ }
+ let targetsCache = null;
+ function targetList() {
+ const now = Math.floor(Date.now() / 1000), minute = Math.floor(now / 60);
+ if (targetsCache && targetsCache.minute === minute) return targetsCache.items;
+ const items = TARGETS.map(tg => {
+ const h1 = rawRounds(tg, now - HOUR, now);
+ const last = h1[h1.length - 1] || {};
+ const item = { id: tg.id, name: tg.name, type: tg.type, host: tg.host, port: tg.port || 0, addr: tg.addr,
+ interval_sec: tg.interval, interval_set: 0, pace: tg.pace, down: !!last.s && last.r === 0,
+ last_1h: stats(h1), last_24h: stats(rawRounds(tg, now - DAY, now).filter((_, i) => i % 4 === 0)) };
+ if (tg.options) item.options = tg.options;
+ if (last.e) item.probe_error = last.e;
+ return item;
+ });
+ targetsCache = { minute, items };
+ return items;
+ }
+
+ // ---- the server's other answers -------------------------------------------
+ const PROBE_TYPES = [
+ { type: 'ping', label: 'PING', uses_port: false, options: [] },
+ { type: 'tcp', label: 'TCP', uses_port: true, options: [] },
+ { type: 'http', label: 'HTTP', uses_port: true, options: [
+ { key: 'scheme', label: 'Scheme', kind: 'choice', choices: ['https', 'http'], default: 'https', help: 'https verifies the certificate; there is deliberately no option to switch that off' },
+ { key: 'method', label: 'Method', kind: 'choice', choices: ['GET', 'HEAD'], default: 'GET' },
+ { key: 'path', label: 'Path', kind: 'string', default: '/', max_len: 200, help: 'Starts with /, for example /health. A query string is allowed: /ping?src=fogping' },
+ { key: 'host_header', label: 'Host header', kind: 'string', max_len: 253, help: 'Ask for a different site on the same address (virtual hosting). Empty = the target\'s host.' },
+ { key: 'expect_status', label: 'Expected status', kind: 'int', max: 599, help: '0 = any status below 400 counts as up. Otherwise only exactly this status does.' },
+ { key: 'follow_redirects', label: 'Follow redirects', kind: 'bool', help: 'Off: a 301 is the answer. On: follow up to 5 redirects and time the whole chain.' },
+ ] },
+ ];
+ const lang = (navigator.language || 'en').toLowerCase();
+ const L = lang.startsWith('zh') ? 'zh' : lang.startsWith('ja') ? 'ja' : 'en';
+ const TXT = {
+ en: { saved: 'This is the demo: changes are not saved. Download fogping to use it for real.',
+ ribbon: 'This is the fogping demo (read-only, simulated data).', dl: 'Download', gh: 'GitHub' },
+ zh: { saved: '这是演示站,修改不会保存。下载 fogping 后即可使用全部功能。',
+ ribbon: '这是 fogping 的在线演示(只读,数据为模拟)。', dl: '下载安装', gh: 'GitHub' },
+ ja: { saved: 'これはデモです。変更は保存されません。fogping をダウンロードするとすべての機能が使えます。',
+ ribbon: 'fogping のオンラインデモです(読み取り専用・シミュレーションデータ)。', dl: 'ダウンロード', gh: 'GitHub' },
+ }[L];
+ const exportFile = () => ({
+ format: 'netping-targets', version: 1, name: 'fogping demo', description: 'The targets of the fogping online demo',
+ targets: TARGETS.map(t => { const o = { name: t.name, type: t.type, host: t.host, pace: t.pace }; if (t.port) o.port = t.port; if (t.options) o.options = t.options; return o; }),
+ });
+
+ const json = (status, body) => new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json; charset=utf-8', 'API-Version': '1' } });
+ const realFetch = window.fetch.bind(window);
+ window.fetch = async (input, init) => {
+ const raw = typeof input === 'string' ? input : input.url;
+ const url = new URL(raw, location.href);
+ const i = url.pathname.indexOf('/api/');
+ if (i < 0) return realFetch(input, init);
+ const path = url.pathname.slice(i + 4), q = url.searchParams;
+ const method = ((init && init.method) || (input && input.method) || 'GET').toUpperCase();
+ if (init && init.signal && init.signal.aborted) throw new DOMException('Aborted', 'AbortError');
+ if (method !== 'GET') return json(403, { error: TXT.saved, code: 'forbidden' });
+ switch (path) {
+ case '/version': return json(200, { version: '', retention_days: RETENTION_DAYS, hot_days: HOT_DAYS, editable: true });
+ case '/probe-types': return json(200, PROBE_TYPES);
+ case '/targets': return json(200, targetList());
+ case '/targets/export': return json(200, exportFile());
+ case '/series': {
+ const tg = byName(q.get('target'));
+ if (!tg) return json(404, { error: 'no such target', code: 'not_found' });
+ const now = Math.floor(Date.now() / 1000);
+ let from, to;
+ if (q.has('from')) { from = +q.get('from'); to = +q.get('to') || now; }
+ else { to = now; from = now - (+q.get('minutes') || 240) * 60; }
+ await new Promise(r => setTimeout(r, 0)); // let an abort from a newer click land first
+ if (init && init.signal && init.signal.aborted) throw new DOMException('Aborted', 'AbortError');
+ return json(200, series(tg, from, Math.min(to, now)));
+ }
+ }
+ return json(404, { error: 'not in the demo', code: 'not_found' });
+ };
+
+ addEventListener('DOMContentLoaded', () => {
+ const b = document.createElement('div');
+ b.className = 'demo-ribbon';
+ b.append(TXT.ribbon + ' ');
+ const a = (href, text) => { const x = document.createElement('a'); x.href = href; x.textContent = text; x.target = '_blank'; x.rel = 'noopener'; return x; };
+ b.append(a('https://github.com/githubflyideas/fogping/releases/latest', TXT.dl), ' · ', a('https://github.com/githubflyideas/fogping', TXT.gh));
+ document.body.prepend(b);
+ const ver = document.getElementById('ver'); if (ver) ver.textContent = 'demo';
+ // The export links are plain downloads, which fetch() never sees: hand out the file here.
+ document.querySelectorAll('a[href$="/api/targets/export"]').forEach(el => el.addEventListener('click', e => {
+ e.preventDefault();
+ const blob = new Blob([JSON.stringify(exportFile(), null, 2)], { type: 'application/json' });
+ const x = document.createElement('a'); x.href = URL.createObjectURL(blob); x.download = 'fogping-targets.json'; x.click();
+ setTimeout(() => URL.revokeObjectURL(x.href), 1000);
+ }));
+ });
+})();