MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / snapshot

Function snapshot

apps/cloud/src/observability/memory-metrics.ts:122–153  ·  view source on GitHub ↗
(now: number, maxQueueSize: number)

Source from the content-addressed store, hash-verified

120});
121
122const snapshot = (now: number, maxQueueSize: number) => {
123 let oldestConnectionAgeMs = 0;
124 let stalledConnections = 0;
125 let ageBuckets = emptyAgeBuckets();
126 const colos = new Set<string>();
127 const scriptVersions = new Set<string>();
128
129 for (const connection of activeSse.values()) {
130 const ageMs = now - connection.startedAt;
131 oldestConnectionAgeMs = Math.max(oldestConnectionAgeMs, ageMs);
132 if (now - connection.lastWriteAt > STALLED_WRITE_MS) stalledConnections += 1;
133 ageBuckets = bucketAge(ageBuckets, ageMs);
134 if (connection.colo) colos.add(connection.colo);
135 if (connection.scriptVersion) scriptVersions.add(connection.scriptVersion);
136 }
137 const sortedColos = Array.from(colos).sort();
138 const sortedScriptVersions = Array.from(scriptVersions).sort();
139
140 return {
141 activeSseConnections: activeSse.size,
142 ageBuckets,
143 oldestConnectionAgeMs,
144 totalBytesForwarded,
145 stalledConnections,
146 stalledWriteThresholdMs: STALLED_WRITE_MS,
147 colo: sortedColos[0] ?? "",
148 colos: sortedColos,
149 scriptVersion: sortedScriptVersions[0] ?? "",
150 scriptVersions: sortedScriptVersions,
151 otel: otelSnapshot(maxQueueSize),
152 };
153};
154
155const emitSnapshot = (event: string, now: number, maxQueueSize: number): void => {
156 lastSnapshotEmittedAt = now;

Callers 1

emitSnapshotFunction · 0.85

Calls 4

emptyAgeBucketsFunction · 0.85
bucketAgeFunction · 0.85
otelSnapshotFunction · 0.85
valuesMethod · 0.80

Tested by

no test coverage detected