MCPcopy
hub / github.com/browserless/browserless / constructor

Method constructor

src/monitoring.ts:373–390  ·  view source on GitHub ↗
(
    protected config: Config,
    statsSource?: MachineStatsSource,
    logFn?: (msg: string) => void,
  )

Source from the content-addressed store, hash-verified

371 protected firstSamplePromise: Promise<void>;
372
373 constructor(
374 protected config: Config,
375 statsSource?: MachineStatsSource,
376 logFn?: (msg: string) => void,
377 ) {
378 super();
379 this.statsSource =
380 statsSource ?? detectMachineStatsSource(config.getMachineStatsSource());
381 const log = logFn ?? ((msg: string) => this.log.info(msg));
382 log(`Machine stats source: ${this.statsSource.name}`);
383
384 this.firstSamplePromise = this.sample();
385 this.samplerHandle = setInterval(() => {
386 this.sample();
387 }, this.config.getCpuSampleIntervalMs());
388 // Don't keep the event loop alive solely for this timer (test runners hang otherwise).
389 this.samplerHandle.unref();
390 }
391
392 protected async sample(): Promise<void> {
393 const { cpu, memory } = await this.statsSource.read();

Callers

nothing calls this directly

Calls 5

sampleMethod · 0.95
detectMachineStatsSourceFunction · 0.85
getMachineStatsSourceMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected