~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/stream

jetstream v2 in zig · mirror of https://tangled.org/zat.dev/stream

0
0
121 lines · 5.0 KB Raw History
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>stream · status</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<meta name="theme-color" content="#040708">
<meta name="description" content="live field report for stream.waow.tech — ingest, archive, and repository state">
<meta property="og:title" content="stream · status">
<meta property="og:description" content="live field report for stream.waow.tech — ingest, archive, and repository state">
<meta property="og:type" content="website">
<meta property="og:url" content="https://stream.waow.tech/status">
<meta name="twitter:card" content="summary">

<link rel="stylesheet" href="/brand.css?v=2">
</head>
<body data-page="status">
<div id="atmosphere" aria-hidden="true"><canvas id="depth" data-current></canvas></div>
<div class="wrap">
<header>
  <a class="brand" href="/">~&nbsp;&nbsp;s t r e a m&nbsp;&nbsp;~</a>
  <span class="livedot" id="live">· connecting</span>
</header>
<main>
  <div class="sect">field report</div>
  <div id="report" class="report">loading…</div>
</main>
<footer>
  <a href="/">home</a>
  <a href="/stats">stats</a>
  <a href="/status" aria-current="page">status</a>
  <a href="/strata/">strata</a>
  <a id="commit" href="https://tangled.org/zat.dev/stream">build</a>
  <a href="https://tangled.org/zat.dev/stream">source</a>
</footer>
</div>
<script src="/ambient.js?v=meander-2"></script>
<script>
const $ = (id) => document.getElementById(id);
let _prevSeq = null;
let _prevSeqAt = 0, _rateEma = null;
try {
  const c = JSON.parse(sessionStorage.getItem("seqCont") || "null");
  if (c && Date.now() - c.t < 60_000 && BigInt(c.seq) > 0n) {
    _prevSeq = BigInt(c.seq); _prevSeqAt = performance.now() - (Date.now() - c.t);
    _rateEma = c.ema;
  }
} catch {}
function saveCont(upN){
  try { sessionStorage.setItem("seqCont", JSON.stringify({ seq: upN.toString(), t: Date.now(), ema: _rateEma })); } catch {}
}
window.__ingestRate = () => _rateEma;
function noteRate(upN){
  const now = performance.now();
  if (_prevSeq !== null && upN > _prevSeq && _prevSeqAt > 0) {
    const inst = Number(upN - _prevSeq) * 1000 / (now - _prevSeqAt);
    _rateEma = _rateEma === null ? inst : 0.6 * _rateEma + 0.4 * inst;
  } else if (upN === _prevSeq) { _rateEma = _rateEma === null ? 0 : 0.6 * _rateEma; }
  _prevSeqAt = now;
}
async function fetchStatus(){
  const t = await (await fetch("/status",{headers:{Accept:"text/plain"},cache:"no-store"})).text();
  const g = (re)=>{const m=t.match(re);return m?m[1]:null};
  const build = g(/build ([0-9a-f]{7,})/);
  if(build && $("commit")){
    $("commit").textContent = build;
    $("commit").href = "https://tangled.org/zat.dev/stream/commits/" + build;
  }
  // honest live-tail signal: the upstream seq must exist AND advance between
  // reads. "state live" from the binary only means the process is serving.
  const up = g(/upstream seq\s+([\d,]+)/);
  const upN = up ? BigInt(up.replace(/,/g,"")) : 0n;
  if (upN > 0n) dispatchEvent(new CustomEvent("stream-sequence", {detail:upN.toString()}));
  const flowing = upN > 0n && _prevSeq !== null && upN > _prevSeq;
  const stalled = upN > 0n && _prevSeq !== null && upN === _prevSeq;
  if (upN > 0n) { noteRate(upN); saveCont(upN); _prevSeq = upN; }
  const rateTxt = _rateEma !== null && _rateEma >= 1 ? " · ≈" + Math.round(_rateEma).toLocaleString() + " events/s" : "";
  if($("live")) $("live").innerHTML =
    flowing ? "<b>●</b> live tail flowing" + rateTxt :
    stalled ? "· live tail stalled · archive serving" :
    upN > 0n ? "· checking tail…" :
    "· live tail paused · archive serving";
  return { t, g };
}

(() => {
  async function tick(){
    try{
      const { t } = await fetchStatus();
      const sections = [];
      for (const block of t.split(/\n\s*\n/)) {
        const lines = block.trim().split('\n');
        if (!lines[0] || lines[0] === 'stream field report' || lines[0].startsWith('build ')) continue;
        const section = document.createElement('section');
        if (!/ {2,}/.test(lines[0])) {
          const heading = document.createElement('h2');
          heading.textContent = lines.shift(); section.append(heading);
        }
        const rows = document.createElement('dl');
        const prose = [];
        for (const line of lines) {
          const pair = line.trim().match(/^(.+?)(?: {2,}| (?=\d))(.+)$/);
          if (pair) {
            const key = document.createElement('dt'), value = document.createElement('dd');
            key.textContent = pair[1]; value.textContent = pair[2]; rows.append(key, value);
          } else prose.push(line.trim());
        }
        if (rows.children.length) section.append(rows);
        if (prose.length) { const paragraph = document.createElement('p'); paragraph.textContent = prose.join(' '); section.append(paragraph); }
        sections.push(section);
      }
      $("report").replaceChildren(...sections);
    }catch(e){ $("report").textContent = "unreachable"; }
  }
  tick(); setInterval(tick, 5000);
})();

</script>
</body>
</html>