useSystemMonitor

Subscribes to system and hardware information streamed from the Fluxlay desktop app. Useful for building cyberpunk HUDs, system monitor wallpapers, and hardware-reactive visuals.

Import

import { useSystemMonitor } from "@fluxlay/react";

Signature

function useSystemMonitor(options?: SystemMonitorOptions): SystemMonitorInfo;

Parameters

SystemMonitorOptions

Per-category polling intervals in milliseconds. Omitted fields use their default values.

PropertyTypeDefaultDescription
cpuIntervalMsnumber500CPU usage, per-core usage, and frequency.
memoryIntervalMsnumber1000Memory and swap usage.
networkIntervalMsnumber1000Network receive/transmit speed.
diskIoIntervalMsnumber2000Disk read/write speed.
diskSpaceIntervalMsnumber30000Disk capacity per mount point.
batteryIntervalMsnumber10000Battery level and charging status.
processIntervalMsnumber10000Running process count.
loadAverageIntervalMsnumber5000System load average.

Shorter intervals increase responsiveness but also increase CPU usage. Adjust the balance to suit your wallpaper's needs.

Return Value

CPU

PropertyTypeDescription
cpuUsagenumberOverall CPU usage percentage (0.0 – 100.0).
cpuPerCorenumber[]Per-core usage percentages (0.0 – 100.0 each).
cpuFrequencyMhznumber[]Per-core clock frequency in MHz.

Memory

PropertyTypeDescription
memoryTotalnumberTotal physical memory in bytes.
memoryUsednumberUsed physical memory in bytes.
memoryUsagenumberMemory usage percentage (0.0 – 100.0).
swapTotalnumberTotal swap space in bytes.
swapUsednumberUsed swap space in bytes.
swapUsagenumberSwap usage percentage (0.0 – 100.0).

Battery

PropertyTypeDescription
batteryLevelnumber | nullBattery charge level (0.0 – 100.0), or null if no battery is present.
batteryChargingboolean | nullWhether the battery is currently charging, or null if no battery.

Network

PropertyTypeDescription
networkRxBytesPerSecnumberNetwork receive speed in bytes per second.
networkTxBytesPerSecnumberNetwork transmit speed in bytes per second.

Disk

PropertyTypeDescription
diskReadBytesPerSecnumberDisk read speed in bytes per second.
diskWriteBytesPerSecnumberDisk write speed in bytes per second.
disksDiskInfo[]Per-mount-point disk capacity information.

DiskInfo:

PropertyTypeDescription
mountPointstringMount point path (e.g. "/").
namestringDisk/volume name.
totalBytesnumberTotal capacity in bytes.
availableBytesnumberAvailable (free) space in bytes.
usagenumberUsage percentage (0.0 – 100.0).

System Info

PropertyTypeDescription
loadAverage[number, number, number]Load average for the past 1, 5, and 15 minutes.
processCountnumberNumber of running processes.
uptimeSecsnumberSystem uptime in seconds.
hostnamestringSystem hostname.
osNamestringOperating system name and version.
cpuBrandstringCPU model name (e.g. "Apple M2 Pro").
physicalCoreCountnumberNumber of physical CPU cores.
logicalCoreCountnumberNumber of logical CPU cores (threads).
cpuArchstringCPU architecture (e.g. "aarch64").
kernelVersionstringKernel version string.

Example

function Wallpaper() {
  const { cpuUsage, memoryUsage, batteryLevel, batteryCharging } = useSystemMonitor({
    cpuIntervalMs: 500,
    memoryIntervalMs: 1000,
    batteryIntervalMs: 10000
  });
 
  // Change background color based on CPU load
  const bg = cpuUsage > 80 ? "#1a0000" : "#000a1a";
 
  return (
    <div style={{ background: bg, color: "white", padding: 32, fontFamily: "monospace" }}>
      <p>CPU: {cpuUsage.toFixed(1)}%</p>
      <p>Memory: {memoryUsage.toFixed(1)}%</p>
      <p>
        Battery: {batteryLevel !== null ? `${batteryLevel.toFixed(0)}%` : "N/A"}
        {batteryCharging ? " ⚡" : ""}
      </p>
    </div>
  );
}

Combining with useProperties

Combine with useProperties to let end users adjust polling intervals.

function Wallpaper() {
  const props = useProperties();
  const info = useSystemMonitor({
    cpuIntervalMs: props.cpuInterval as number
  });
  // ...
}

Notes

  • Each category is only refreshed and read at its configured interval. Cached values are used between refreshes.
  • No data is sent to the stream on ticks where nothing was updated, so the effective receive rate matches the shortest configured interval.
  • Static information (hostname, OS name, CPU model, etc.) is fetched once at app startup and never changes.
  • Monitoring starts when the first subscriber connects and stops when all subscribers disconnect.
  • This hook only works inside the Fluxlay desktop app. In a normal browser, it returns the initial zero values.
  • When options values change, the stream is automatically reconnected.