MCPcopy
hub / github.com/browserless/browserless / detectMachineStatsSource

Function detectMachineStatsSource

src/monitoring.ts:335–357  ·  view source on GitHub ↗
(
  preference: 'auto' | 'host' | 'cgroup',
  fileExists: FileExists = defaultFileExists,
)

Source from the content-addressed store, hash-verified

333];
334
335export function detectMachineStatsSource(
336 preference: 'auto' | 'host' | 'cgroup',
337 fileExists: FileExists = defaultFileExists,
338): MachineStatsSource {
339 if (preference === 'host') return new HostSource();
340
341 const hasAll = (paths: string[]) => paths.every((p) => fileExists(p));
342 const hasV2 = hasAll(CGROUP_V2_REQUIRED);
343 const hasV1 = !hasV2 && hasAll(CGROUP_V1_REQUIRED);
344
345 if (preference === 'cgroup') {
346 if (hasV2) return new CgroupV2Source();
347 if (hasV1) return new CgroupV1Source();
348 throw new Error(
349 'MACHINE_STATS_SOURCE=cgroup but required cgroup stat files are missing.',
350 );
351 }
352
353 // 'auto'
354 if (hasV2) return new CgroupV2Source();
355 if (hasV1) return new CgroupV1Source();
356 return new HostSource();
357}
358
359export class Monitoring extends EventEmitter {
360 protected log = new Logger('hardware');

Callers 2

monitoring.spec.tsFile · 0.85
constructorMethod · 0.85

Calls 1

hasAllFunction · 0.85

Tested by

no test coverage detected