UNPKG

@crawlee/core

Version:

The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.

27 lines (26 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCpuLoadSignal = createCpuLoadSignal; const load_signal_1 = require("./load_signal"); /** * Tracks CPU usage via `SYSTEM_INFO` events and reports overload when * the platform or local OS metrics indicate the CPU is overloaded. */ function createCpuLoadSignal(options) { return load_signal_1.SnapshotStore.fromEvent({ name: 'cpuInfo', overloadedRatio: options.overloadedRatio ?? 0.4, events: options.config.getEventManager(), event: "systemInfo" /* EventType.SYSTEM_INFO */, snapshotHistoryMillis: options.snapshotHistoryMillis, handler(store, systemInfo) { const { cpuCurrentUsage, isCpuOverloaded } = systemInfo; const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date(); store.push({ createdAt, isOverloaded: isCpuOverloaded, usedRatio: Math.ceil(cpuCurrentUsage / 100), }, createdAt); }, }); }