MCPcopy
hub / github.com/browserless/browserless / readMemory

Method readMemory

src/monitoring.ts:146–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

144 }
145
146 protected async readMemory(): Promise<number | null> {
147 let currentContent: string;
148 let maxContent: string;
149 try {
150 [currentContent, maxContent] = await Promise.all([
151 readWithTimeout('/sys/fs/cgroup/memory.current', this.readFile),
152 readWithTimeout('/sys/fs/cgroup/memory.max', this.readFile),
153 ]);
154 } catch (err) {
155 this.logOnce('memory-read', err);
156 return null;
157 }
158
159 const current = Number(currentContent.trim());
160 const max = parseMemoryMax(maxContent);
161 if (!Number.isFinite(current) || max === null || max <= 0) {
162 this.logOnce('memory-parse', new Error('cgroup v2 memory parse failed'));
163 return null;
164 }
165 return current / max;
166 }
167
168 protected logOnce(category: string, err: unknown) {
169 if (this.loggedFailure.has(category)) return;

Callers 1

readMethod · 0.95

Calls 3

logOnceMethod · 0.95
readWithTimeoutFunction · 0.85
parseMemoryMaxFunction · 0.85

Tested by

no test coverage detected