Cosmo

System Resources

Monitor system resources like CPU, memory, and battery.

System Resources

The systemResources module allows you to access real-time system information.

Usage

import { systemResources } from "@buildcosmo/widget";

getSystemCpu()

Retrieves the current CPU usage percentage.

Usage

const cpuUsage = await systemResources.getSystemCpu();
console.log(`CPU Usage: ${cpuUsage}%`);

Returns

  • Promise<number>: The current CPU usage as a percentage (0-100).

getSystemMemory()

Retrieves the current memory usage.

Usage

const [used, total] = await systemResources.getSystemMemory();
const usedGB = (used / (1024 * 1024 * 1024)).toFixed(2);
const totalGB = (total / (1024 * 1024 * 1024)).toFixed(2);

console.log(`Memory: ${usedGB}GB / ${totalGB}GB`);

Returns

  • Promise<[number, number]>: A tuple containing:
    1. used: Used memory in bytes.
    2. total: Total memory in bytes.

getSystemBattery()

Retrieves the current battery status.

Usage

const [percentage, isCharging, remainingTime] = await systemResources.getSystemBattery();

console.log(`Battery: ${percentage}%`);
console.log(`Charging: ${isCharging}`);
console.log(`Time remaining: ${remainingTime} minutes`);

Returns

  • Promise<[number, boolean, number]>: A tuple containing:
    1. percentage: Battery level as a percentage (0-100).
    2. isCharging: true if the device is plugged in, false otherwise.
    3. remainingTime: Estimated time remaining in minutes. Returns -1 if unknown.