- Web Server reads static files inline; proxy middleware chain flattened - About window with license summary and project links; AGPL-3.0-or-later - Rewritten documentation: feature list, screenshots, performance guide - Fix false spikes in per-Vhost request-rate charts
35 lines
1.9 KiB
JavaScript
35 lines
1.9 KiB
JavaScript
// Shared rate sampling: rebase after background-tab pauses instead of plotting a false spike.
|
|
const rustProxyRateSampling = (() => {
|
|
let generation = 0;
|
|
const pause = () => { generation += 1; };
|
|
document.addEventListener?.("visibilitychange", () => { if (document.hidden) pause(); });
|
|
window.addEventListener?.("pagehide", pause);
|
|
function cadence(key) {
|
|
const value = window.rustProxyRefresh?.current?.()?.[key];
|
|
const fallback = key === "cache_seconds" ? 5 : 3;
|
|
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
}
|
|
function stamp(at) { return { at, generation }; }
|
|
function continuous(previous, at, intervalSeconds = 3) {
|
|
const seconds = Number.isFinite(intervalSeconds) && intervalSeconds > 0 ? intervalSeconds : 3;
|
|
return Boolean(previous && !document.hidden && previous.generation === generation &&
|
|
Number.isFinite(at) && Number.isFinite(previous.at) && at > previous.at &&
|
|
at - previous.at <= Math.max(10000, seconds * 3000));
|
|
}
|
|
function difference(previous, values, at, intervalSeconds = 3) {
|
|
if (previous && previous.generation === generation && Number.isFinite(at) &&
|
|
Number.isFinite(previous.at) && at >= previous.at && at - previous.at < 250) {
|
|
return { next: previous, deltas: null, seconds: null, rapid: true };
|
|
}
|
|
const next = { ...stamp(at), values: [...values] };
|
|
if (!continuous(previous, at, intervalSeconds) ||
|
|
values.some((value, i) => !Number.isFinite(value) || value < 0 ||
|
|
!Number.isFinite(previous.values[i]) || value < previous.values[i])) {
|
|
return { next, deltas: null, seconds: null };
|
|
}
|
|
return { next, deltas: values.map((value, i) => value - previous.values[i]),
|
|
seconds: (at - previous.at) / 1000 };
|
|
}
|
|
return { cadence, stamp, continuous, difference };
|
|
})();
|