diff --git a/README.md b/README.md index 45ee9aa..c92be71 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,10 @@ first `start` with this recipe, kill the old process groups (`kill -s TERM -- -< - **Runners column.** Every runner the forges report, plus any seen in job data, and a line for this device's gitlab-runner when `runner_metrics` is set. - **Phone health.** Battery, plugged state, temperature, CPU (Termux's own processes on a phone, the whole system on a Linux host) and memory, plus a 24 h - battery and temperature chart. A new failure on main or staging vibrates the phone once. + chart: battery, CPU and memory on a 0-100% scale, temperature on its own scale, and a band for each job + this device ran (a red tick on top for a failed one, dashed edges for a GitLab busy span, which is only + known to the poll interval). A host without a battery gets the same chart as "This host", without battery + and temperature. A new failure on main or staging vibrates the phone once. | Waiting, stalled queue | On hold (manual) | |---|---| diff --git a/board/index.html b/board/index.html index 7b0090e..f3e26ac 100644 --- a/board/index.html +++ b/board/index.html @@ -22,6 +22,12 @@ --queue: #f29a3a; --hold: #7cb7e8; --off: #3a3f46; + /* 24 h chart series: three line hues validated as a set on --board-deep (lightness band, CVD and + normal-vision separation, 3:1 contrast); battery is an area wash, so its form tells it apart */ + --s-temp: #d28e05; + --s-cpu: #338ced; + --s-mem: #e24d8b; + --s-batt: #0aac23; --sans: "Roboto Condensed", sans-serif-condensed, "Arial Narrow", sans-serif; --mono: "Roboto Mono", "Droid Sans Mono", "DejaVu Sans Mono", monospace; } @@ -129,12 +135,29 @@ .side > .chart { flex: 1 1 auto; display: flex; flex-direction: column; } .chart .plot { position: relative; flex: 1 1 0; min-height: 14vh; } .chart svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; } -/* scale marks: battery on the left edge, temperature on the right; both scales share the three lines */ -.chart .tick { position: absolute; font-size: 1.7vh; line-height: 1; color: var(--dim); opacity: .8; padding: .3vh .4vw; pointer-events: none; } +/* scale marks: 0-100 % (battery, CPU, memory) on the left edge, temperature on the right; the scales share + the three lines */ +/* a halo in the surface colour keeps them readable where a line or a band passes under them (14vh minimum) */ +.chart .tick { position: absolute; font-size: 1.7vh; line-height: 1; color: var(--dim); padding: .3vh .4vw; pointer-events: none; + text-shadow: 0 0 .3vh var(--board-deep), 0 0 .3vh var(--board-deep), 0 0 .3vh var(--board-deep), 0 0 .6vh var(--board-deep); } .chart .tick.l { left: 0; } .chart .tick.r { right: 0; } .chart .tick.y0 { top: 0; } .chart .tick.y1 { top: 50%; transform: translateY(-100%); } .chart .tick.y2 { bottom: 0; } -.legend { display: flex; gap: 1.4vw; font-size: 2.2vh; color: var(--dim); margin-top: .5vh; } -.legend i { display: inline-block; width: 1.8vh; height: .5vh; vertical-align: middle; margin-right: .3vw; } +/* the jobs this device ran, behind the series: neutral bands; a failed job adds a red tick along the top, + an approximate span (busy between two polls) is fainter with dashed edges */ +.chart .run rect { fill: var(--text); fill-opacity: .11; } +.chart .run.fail rect { fill: var(--fail); fill-opacity: .2; } +.chart .run.approx rect { fill-opacity: .06; } +.chart .run .cap { stroke: var(--fail); stroke-width: 6px; } +.chart .run .edge { stroke: var(--dim); stroke-width: 1px; stroke-dasharray: 3 3; stroke-opacity: .8; } +.chart .series { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; } +.legend { display: flex; flex-wrap: wrap; column-gap: 1.4vw; row-gap: .3vh; font-size: 2.2vh; color: var(--dim); margin-top: .5vh; } +.legend span { white-space: nowrap; } +.legend i { display: inline-block; width: 1.8vh; height: .5vh; vertical-align: middle; margin-right: .3vw; background: var(--k); } +.legend i.dash { height: 0; background: none; border-top: .3vh dashed var(--k); } +.legend i.area { height: 1.4vh; opacity: .45; } +.legend i.band { width: 1.4vh; height: 1.4vh; background: color-mix(in srgb, var(--text) 16%, transparent); } +.legend i.band.fail { background: color-mix(in srgb, var(--fail) 26%, transparent); border-top: .4vh solid var(--fail); } +.legend i.band.approx { background: color-mix(in srgb, var(--text) 8%, transparent); border: 1px dashed var(--dim); border-top: 0; border-bottom: 0; } footer { grid-column: 1 / -1; display: flex; gap: 2vw; padding: .9vh 2.4vw; font-size: 2.2vh; color: var(--dim); background: var(--board-deep); } footer .err { color: var(--fail); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } @@ -456,26 +479,96 @@ }; $("fleet").innerHTML = fleet.length || lr ? `

Runners

` + local + fleet.map(f => `
${name(f.name)}${esc(what(f))}
`).join("") : ""; - renderChart(st.device_history || []); + renderChart(st.device_history || [], st.device_runs || [], st.device || {}); } -function renderChart(h) { - if (h.length < 2) { $("chart").innerHTML = `

Phone, last 24 h

The chart shows up after 10 minutes of samples.

`; return; } - const W = 400, H = 100, now = Date.now() / 1000, x = t => W * (1 - (now - t) / 86400); +// The 24 h chart. Left scale 0-100 %: battery (area wash), CPU and memory (lines); right scale 20-50°: +// temperature, with the 40° warning line. Behind them, one band per job this device ran (device_runs), from +// start to end (to now while it runs): a failed job adds a tick along the top, an approximate span (a busy +// count seen between two polls, without project, job or result) is fainter with dashed edges. A series with +// no data is left out with its scale, line and legend entry: a host without a battery shows CPU, memory and +// its runs under "This host". A missing value or a gap in the samples breaks a line instead of bridging it. +const hhmm = t => new Date(t * 1000).toLocaleTimeString("en-GB", {hour: "2-digit", minute: "2-digit"}); +function chartPaths(h, key, x, y, area, H) { + // consecutive samples with a value, split where one is missing or the gap is over 2.5 sample spacings + // (never under 15 min); a lone sample still draws as a dot (round cap) + const gaps = h.slice(1).map((s, i) => s.t - h[i].t).sort((p, q) => p - q); + const maxGap = Math.max(900, 2.5 * (gaps[gaps.length >> 1] || 0)); + const segs = []; + let cur = null, prev = null; + for (const s of h) { + const v = s[key]; + if (typeof v !== "number" || !Number.isFinite(v)) { cur = null; continue; } + if (!cur || s.t - prev > maxGap) segs.push(cur = []); + cur.push([x(s.t).toFixed(1), y(v).toFixed(1)]); + prev = s.t; + } + return segs.map(g => area + ? `M${g[0][0]},${H} ${g.map(([px, py]) => `L${px},${py}`).join(" ")} L${g.at(-1)[0]},${H}Z` + : `M${g[0][0]},${g[0][1]} ${(g.length > 1 ? g.slice(1) : g).map(([px, py]) => `L${px},${py}`).join(" ")}`).join(" "); +} +function runBands(runs, now, x, W, H) { + const from = now - 86400; + const unit = W / Math.max(1, $("chart").clientWidth); // viewBox units per CSS pixel + const shown = runs.filter(r => Number.isFinite(r.start) && r.start <= now && (r.end ?? now) >= from); + const svg = shown.map(r => { + let a = x(Math.max(r.start, from)), b = x(Math.min(r.end ?? now, now)); + const fail = r.result === "failed", min = (fail ? 4 : 2) * unit; // a short job stays 2 px wide, a failed one 4 px + if (b - a < min) { const m = (a + b) / 2; a = m - min / 2; b = m + min / 2; } + const when = `${hhmm(r.start)}–${r.end == null ? "now" : hhmm(r.end)}`; + const what = r.approx ? `${r.forge || "runner"} busy (approximate)` : [short(r.project), r.job, r.result || (r.end == null ? "running" : "")].filter(Boolean).join(" · "); + const [x0, w] = [a.toFixed(2), (b - a).toFixed(2)]; + return `${esc(`${what}, ${when}`)}${ + fail ? `` : ""}${ + r.approx ? [a, b].map(e => ``).join("") : ""}`; + }).join(""); + return {svg, n: shown.length, failed: shown.filter(r => r.result === "failed").length, + approx: shown.filter(r => r.approx).length, open: shown.filter(r => r.end == null).length}; +} +function renderChart(h, runs, device) { + const has = k => h.some(s => typeof s[k] === "number"); + const battery = has("battery") || device.battery != null; + const title = `

${battery ? "Phone" : "This host"}, last 24 h

`; + const now = Date.now() / 1000; + if (h.length < 2 && !runs.some(r => (r.end ?? now) >= now - 86400)) { + $("chart").innerHTML = `${title}

The chart shows up after 10 minutes of samples.

`; return; + } + const W = 400, H = 100, x = t => W * (1 - (now - t) / 86400); const yT = v => H - H * Math.min(1, Math.max(0, (v - 20) / 30)); // 20° to 50° - const yB = v => H - H * v / 100; - const temp = h.filter(s => s.temp != null).map(s => `${x(s.t).toFixed(1)},${yT(s.temp).toFixed(1)}`).join(" "); - const bat = h.filter(s => s.battery != null); - const area = bat.length ? `M${x(bat[0].t).toFixed(1)},${H} ` + bat.map(s => `L${x(s.t).toFixed(1)},${yB(s.battery).toFixed(1)}`).join(" ") + ` L${x(bat.at(-1).t).toFixed(1)},${H}Z` : ""; - $("chart").innerHTML = `

Phone, last 24 h

-
+ const yP = v => H - H * Math.min(100, Math.max(0, v)) / 100; // 0 to 100 % + const temp = has("temp"), bands = runBands(runs, now, x, W, H); + const series = [ // [key, label, colour, legend key style, scale] + ["battery", "battery", "--s-batt", "area", yP], + ["cpu", "CPU", "--s-cpu", "", yP], + ["mem", "memory", "--s-mem", "", yP], + ["temp", "temperature", "--s-temp", "", yT], + ].filter(([k]) => has(k)); + const pct = series.filter(([k]) => k !== "temp").map(([, l]) => l); + const lines = series.map(([k, , c, st, y]) => st === "area" + ? `` + : ``).join(""); + const jobs = bands.n ? `Shaded bands: ${bands.n} ${bands.n === 1 ? "job" : "jobs"} this device ran${ + [bands.failed && `${bands.failed} failed (red tick on top)`, bands.approx && `${bands.approx} approximate busy ${bands.approx === 1 ? "span" : "spans"} (dashed edges)`, + bands.open && `${bands.open} still running`].filter(Boolean).map(t => `, ${t}`).join("")}.` : "No jobs ran on this device in the last 24 hours."; + const label = [`${battery ? "Phone" : "This host"}, last 24 hours.`, + pct.length ? `Left scale 0 to 100%: ${pct.join(", ")}.` : "", + temp ? "Right scale 20 to 50°: temperature, with a dashed line at 40°." : "", jobs].filter(Boolean).join(" "); + const legend = [ + ...series.map(([, l, c, st]) => [l, c, st]), + ...(temp ? [["40°", "--queue", "dash"]] : []), + ...(bands.n ? [["job", "", "band"]] : []), + ...(bands.failed ? [["failed", "", "band fail"]] : []), + ...(bands.approx ? [["approx.", "", "band approx"]] : []), + ].map(([l, c, st]) => `${esc(l)}`).join(""); + $("chart").innerHTML = `${title} +
+ ${bands.svg} ${[0, H / 2, H].map(y => ``).join("")} - - - - ${[["100%", "50°"], ["50%", "35°"], ["0%", "20°"]].map(([b, t], i) => - `${b}${t}`).join("")}
-
temperaturebattery40°
`; + ${temp ? `` : ""} + ${lines} + ${[["100%", "50°"], ["50%", "35°"], ["0%", "20°"]].map(([p, t], i) => + `${p}${temp ? `${t}` : ""}`).join("")}
+
${legend}
`; } function fitSide() { diff --git a/board/tests/test_fixes.py b/board/tests/test_fixes.py index 68eb62c..af6f0ec 100644 --- a/board/tests/test_fixes.py +++ b/board/tests/test_fixes.py @@ -168,6 +168,20 @@ def test_local_runner_line(self): ]) + +class DeviceChart(unittest.TestCase): + @unittest.skipUnless(shutil.which("node"), "node not installed") + def test_chart_line_breaks_on_missing_values_and_gaps(self): + # a null or absent value (macOS cpu, samples older than cpu/mem) and a gap of over 15 min break the line + # instead of drawing it to zero or bridging it; a lone sample stays a dot + html = (HERE / "index.html").read_text() + fn = re.search(r"function chartPaths\(.*?\n\}", html, re.S).group(0) + h = [{"t": 0, "cpu": 10}, {"t": 300, "cpu": 20}, {"t": 600, "cpu": None}, {"t": 900, "cpu": 30}, + {"t": 1200}, {"t": 1500, "cpu": 40}, {"t": 1800, "cpu": 50}, {"t": 4800, "cpu": 60}] + js = f"{fn}\nconsole.log(chartPaths({json.dumps(h)}, 'cpu', t => t / 100, v => v, false, 100))" + out = subprocess.run(["node", "-e", js], capture_output=True, text=True, check=True).stdout.strip() + self.assertEqual(out, "M0.0,10.0 L3.0,20.0 M9.0,30.0 L9.0,30.0 M15.0,40.0 L18.0,50.0 M48.0,60.0 L48.0,60.0") + class NeutralDefaults(unittest.TestCase): def test_no_local_runner_logs_by_default(self): self.assertFalse(hasattr(server, "GH_LOGS")) diff --git a/docs/screenshots/board-failure-1920x1080.png b/docs/screenshots/board-failure-1920x1080.png index 0d2b032..083456e 100644 Binary files a/docs/screenshots/board-failure-1920x1080.png and b/docs/screenshots/board-failure-1920x1080.png differ diff --git a/docs/screenshots/board-failure-915x412-2x.png b/docs/screenshots/board-failure-915x412-2x.png index 33d8869..3d9d8f5 100644 Binary files a/docs/screenshots/board-failure-915x412-2x.png and b/docs/screenshots/board-failure-915x412-2x.png differ diff --git a/docs/screenshots/board-idle-1920x1080.png b/docs/screenshots/board-idle-1920x1080.png index 3f6d887..690695b 100644 Binary files a/docs/screenshots/board-idle-1920x1080.png and b/docs/screenshots/board-idle-1920x1080.png differ diff --git a/docs/screenshots/board-idle-915x412-2x.png b/docs/screenshots/board-idle-915x412-2x.png index b2cad1e..e994427 100644 Binary files a/docs/screenshots/board-idle-915x412-2x.png and b/docs/screenshots/board-idle-915x412-2x.png differ diff --git a/docs/screenshots/board-on-hold-1920x1080.png b/docs/screenshots/board-on-hold-1920x1080.png index 99a20d5..a14f808 100644 Binary files a/docs/screenshots/board-on-hold-1920x1080.png and b/docs/screenshots/board-on-hold-1920x1080.png differ diff --git a/docs/screenshots/board-on-hold-915x412-2x.png b/docs/screenshots/board-on-hold-915x412-2x.png index 7c9fd39..a8c4b16 100644 Binary files a/docs/screenshots/board-on-hold-915x412-2x.png and b/docs/screenshots/board-on-hold-915x412-2x.png differ diff --git a/docs/screenshots/board-running-1920x1080.png b/docs/screenshots/board-running-1920x1080.png index 46d237c..80e81d2 100644 Binary files a/docs/screenshots/board-running-1920x1080.png and b/docs/screenshots/board-running-1920x1080.png differ diff --git a/docs/screenshots/board-running-915x412-2x.png b/docs/screenshots/board-running-915x412-2x.png index 0b983c6..4df93e0 100644 Binary files a/docs/screenshots/board-running-915x412-2x.png and b/docs/screenshots/board-running-915x412-2x.png differ diff --git a/docs/screenshots/board-waiting-1920x1080.png b/docs/screenshots/board-waiting-1920x1080.png index 1cfd2f9..f4838b3 100644 Binary files a/docs/screenshots/board-waiting-1920x1080.png and b/docs/screenshots/board-waiting-1920x1080.png differ diff --git a/docs/screenshots/board-waiting-915x412-2x.png b/docs/screenshots/board-waiting-915x412-2x.png index 6b11ebc..e1b0189 100644 Binary files a/docs/screenshots/board-waiting-915x412-2x.png and b/docs/screenshots/board-waiting-915x412-2x.png differ diff --git a/docs/screenshots/make_screenshots.py b/docs/screenshots/make_screenshots.py index ec9c004..e728761 100755 --- a/docs/screenshots/make_screenshots.py +++ b/docs/screenshots/make_screenshots.py @@ -137,32 +137,73 @@ def raw_state(pipelines, runners=RUNNERS, device=DEVICE, running=0, errors=()): "device": dict(device), "runner": {"configured": True, "up": True, "running": running, "name": "phone-runner"}} -def history(temp_peak=36.0, low_batt=False): +def gh_run(project, name, ago, secs, result): + """One exact job from a local GitHub runner log: started `ago` seconds before NOW, ran `secs`.""" + return {"forge": "github", "project": project, "job": name, "start": NOW - ago, + "end": NOW - ago + secs if secs is not None else None, "result": result if secs is not None else None, + "approx": False} + + +def gl_span(ago, secs): + """One approximate busy span from gitlab-runner metrics: no project, job or result.""" + return {"forge": "gitlab", "project": None, "job": None, "start": NOW - ago, + "end": NOW - ago + secs if secs is not None else None, "result": None, "approx": True} + + +# the jobs this device ran over the last 24 h (device_runs), oldest first: exact GitHub jobs (one failed, one +# canceled) and approximate GitLab busy spans +RUNS = [ + gh_run("acme/mobile", "android", 84000, 540, "success"), + gl_span(80000, 1500), + gh_run("lib/utils", "ci", 60000, 95, "success"), + gh_run("lib/parser", "ci", 50000, 900, "failed"), + gl_span(43000, 900), + gl_span(30000, 2400), + gh_run("acme/mobile", "android", 21600, 610, "success"), + gl_span(14400, 600), + gh_run("acme/mobile", "android", 9000, 590, "canceled"), + gh_run("acme/docs-site", "pages", 3600, 140, "success"), +] + + +def history(temp_peak=36.0, low_batt=False, runs=RUNS): + """Device samples every 5 min; CPU and memory rise while a job runs. The board was stopped for 45 min + around 06:00 (no samples there), so every line breaks instead of bridging the gap.""" out = [] for i in range(0, 86400, 300): h = i / 3600 + if 15.5 <= h < 16.25: + continue + t = NOW - 86400 + i + busy = any(r["start"] <= t <= (r["end"] if r["end"] is not None else NOW) for r in runs) bump = math.exp(-((h - 15) / 2.2) ** 2) # afternoon usage peak temp = 31 + (temp_peak - 31) * bump + 0.6 * math.sin(h * 1.3) batt = max(20, 80 - (h - 9) * 3.6) if low_batt and h > 9 else 80 + 1.5 * math.sin(h * 0.8) - out.append({"t": NOW - 86400 + i, "temp": round(temp, 1), "battery": round(batt)}) + cpu = (56 + 6 * math.sin(h * 3)) if busy else 4 + 2 * abs(math.sin(h * 2.1)) + mem = (64 + 3 * math.sin(h)) if busy else 41 + 3 * math.sin(h * 0.7) + out.append({"t": t, "temp": round(temp, 1), "battery": round(batt), "cpu": round(cpu), "mem": round(mem)}) return out -def finish(raw, hist=None): +def finish(raw, hist=None, runs=RUNS): """raw poller output -> /api/state, through the board's own build_state (throwaway store, no vibration).""" store = Store(Path(tempfile.gettempdir()) / "mini-runner-screenshots-unused.json") # never saved st = server.build_state(json.loads(json.dumps(raw)), store, NOW, lambda: None) st["updated"] = NOW - 4 - st["device_history"] = hist or history() + st["device_history"] = hist or history(runs=runs) + st["device_runs"] = runs return st +RUNS_OPEN = RUNS + [gl_span(1500, None)] # still running: the band reaches now + + def scenes(): hot = {**DEVICE, "battery": 78, "temp": 38.6, "cpu_pct": 61, "mem_used_pct": 67} return { # a job running on the phone, another on a build box; the rest of the board finished "running": finish(raw_state([web_app(2, 128), mobile_running(), *DONE], device=hot, running=1), - history(temp_peak=39)), + history(temp_peak=39, runs=RUNS_OPEN), RUNS_OPEN), # jobs ready for a runner for 7 min while every runner idles: the stalled-queue alert "waiting": finish(raw_state([ pipe("acme/api", "staging", "queued", 30, [ diff --git a/docs/screenshots/queue-moving.gif b/docs/screenshots/queue-moving.gif index e425061..ecdedb5 100644 Binary files a/docs/screenshots/queue-moving.gif and b/docs/screenshots/queue-moving.gif differ