I deleted a monitoring dependency that wedged my own event loop
I run a local command console that probes twelve app URLs every sixty seconds and shows live CPU/RAM/disk gauges. It used to depend on systeminformation — a popular Node package that reads OS telemetry through native bindings and, on Windows, through WMI queries. It never failed loudly. It just quietly took over. Every poll to /api/system would hang for a few hundred milliseconds. After a few…
The author of this console monitors twelve app URLs every 60 seconds, displaying live CPU, RAM, and disk gauges. For this purpose, the console relied on a popular Node package named systeminformation. This package read OS telemetry using native bindings with WMI queries on Windows. However, running systeminformation silently took over the event loop.
Every time the console polled /api/system, it would hang for a few hundred milliseconds. Over time, the entire console stopped responding, not just the telemetry route. Health probes, project catalogs, and even the root GET endpoint were affected. Restarting the process fixed the issue temporarily, but the hung poll kept piling up.
After a weekend spent chasing a Vercel edge issue, the author discovered that the real bottleneck was running on their own laptop. Utilizing systeminformation proved useful as it provided CPU, memory, disk, battery, processes, and more through a simple API. However, running it on a timer with setInterval led to calling WMI queries every two seconds.
While WMI calls did not block directly, the callbacks parsing and assigning results ran on the event loop, causing issues. When a query hung, subsequent queries stacked up, and the event loop became wedged. This behavior mimicked the app being slow instead of dead. Health probes timed out, the frontend spinner spun indefinitely, and additional logging only blamed the network.
Restarting the app worked temporarily until the issue resurfaced. To resolve this, the author replaced systeminformation with Node's built-in os module and fs.statfsSync. These modules had no native bindings, no WMI, and no possibility of hanging the event loop. The sampleSystem function used os.totalmem(), os.freemem(), and fs.statfsSync to gather system statistics. This replacement eliminated the event loop bottleneck, ensuring the console remained responsive.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to