fix(traffic): сохранять историю и показывать достоверную свежесть
This commit is contained in:
1 parent
ebe62ae2ef
commit
1275dd7b9b
48 files changed
+1899
-187
No files matched your search
@@ -1,4 +1,5 @@
|
||||
/** Чистые формулы трафика: дельты счётчиков, корзины series, monitor-traffic. */
|
||||
import { mergeTrafficObservations } from "./traffic-freshness.js"
|
||||
|
||||
export const SERIES_POINTS = 60
|
||||
|
||||
@@ -12,6 +13,7 @@ export interface TrafficSampleLike {
|
||||
txBps: number
|
||||
running: boolean
|
||||
disabled: boolean
|
||||
countersKnown?: boolean
|
||||
}
|
||||
|
||||
export interface RatePoint {
|
||||
@@ -20,7 +22,8 @@ export interface RatePoint {
|
||||
txMbps: number
|
||||
}
|
||||
|
||||
export interface TrafficObservations {rxNow:boolean;txNow:boolean;rxSeries:boolean[];txSeries:boolean[];sampledAt:string|null}
|
||||
export interface TrafficObservations {rxNow:boolean;txNow:boolean;rxSeries:boolean[];txSeries:boolean[];sampledAt:string|null;expiresAt?:string|null;
|
||||
currentState?: import("./traffic-freshness.js").TrafficCurrentState;lastAttemptAt?:string|null;lastSucceededAt?:string|null;error?:string|null}
|
||||
|
||||
export interface BuiltTrafficSeries {
|
||||
observations?:TrafficObservations
|
||||
@@ -161,7 +164,7 @@ export function buildTrafficFromSamples(
|
||||
continue
|
||||
}
|
||||
|
||||
const sorted = [...arr].sort((a, b) => a.sampledAt.localeCompare(b.sampledAt))
|
||||
const sorted = [...arr].sort((a, b) => Date.parse(a.sampledAt) - Date.parse(b.sampledAt))
|
||||
const last = sorted[sorted.length - 1]
|
||||
if (!last) continue
|
||||
if (!allowList && (!last.running || last.disabled)) continue
|
||||
@@ -169,14 +172,6 @@ export function buildTrafficFromSamples(
|
||||
includedSeries++
|
||||
if (last.running && !last.disabled) sessions += 1
|
||||
|
||||
const first = sorted[0]
|
||||
if (first) {
|
||||
const dRx = last.rxBytes - first.rxBytes
|
||||
const dTx = last.txBytes - first.txBytes
|
||||
rxBytesDelta += dRx >= 0 ? dRx : last.rxBytes
|
||||
txBytesDelta += dTx >= 0 ? dTx : last.txBytes
|
||||
}
|
||||
|
||||
for (let i = 1; i < sorted.length; i++) {
|
||||
const prev = sorted[i - 1]
|
||||
const cur = sorted[i]
|
||||
@@ -185,8 +180,13 @@ export function buildTrafficFromSamples(
|
||||
const t0 = parseIsoMs(prev.sampledAt)
|
||||
const t1 = parseIsoMs(cur.sampledAt)
|
||||
if(Number.isFinite(Date.parse(cur.sampledAt))&&t1>=rangeStartMs&&t1<=rangeEndMs)lastAttemptAt=Math.max(lastAttemptAt??t1,t1)
|
||||
const rxBps = rateBpsFromDelta(prev.rxBytes, cur.rxBytes, t0, t1)
|
||||
const txBps = rateBpsFromDelta(prev.txBytes, cur.txBytes, t0, t1)
|
||||
const countersKnown = prev.countersKnown !== false && cur.countersKnown !== false
|
||||
const rxBps = countersKnown ? rateBpsFromDelta(prev.rxBytes, cur.rxBytes, t0, t1) : null
|
||||
const txBps = countersKnown ? rateBpsFromDelta(prev.txBytes, cur.txBytes, t0, t1) : null
|
||||
if (t1 >= rangeStartMs && t1 <= rangeEndMs) {
|
||||
if (rxBps !== null) rxBytesDelta += cur.rxBytes - prev.rxBytes
|
||||
if (txBps !== null) txBytesDelta += cur.txBytes - prev.txBytes
|
||||
}
|
||||
if (rxBps == null && txBps == null) continue
|
||||
const rxMbps = bpsToMbps(rxBps ?? 0)
|
||||
const txMbps = bpsToMbps(txBps ?? 0)
|
||||
@@ -269,7 +269,7 @@ export function mergeBuiltTraffic(parts: BuiltTrafficSeries[]): BuiltTrafficSeri
|
||||
}
|
||||
acc.rxTotalGiB = Number(acc.rxTotalGiB.toFixed(1))
|
||||
acc.txTotalGiB = Number(acc.txTotalGiB.toFixed(1))
|
||||
return acc
|
||||
return parts.every(p => p.observations) ? { ...acc, observations: mergeTrafficObservations(parts.map(p => p.observations!)) } : acc
|
||||
}
|
||||
|
||||
export function parseMonitorTraffic(
|
||||
|
||||
Reference in new issue
Block a user