Skip to content

Instantly share code, notes, and snippets.

@YohannesTz
Created May 6, 2024 11:37
Show Gist options
  • Save YohannesTz/de9d8d97f5cd5daf572abab3832192a6 to your computer and use it in GitHub Desktop.
Save YohannesTz/de9d8d97f5cd5daf572abab3832192a6 to your computer and use it in GitHub Desktop.
System info for Nodejs host app
const os = require('os');
const si = require('systeminformation');
const getHardwareHealth = async () => {
const cpu = os.cpus();
const totalMemoryBytes = os.totalmem();
const freeMemoryBytes = os.freemem();
const totalMemoryMb = Math.round(totalMemoryBytes / 1024 / 1024);
const freeMemoryMb = Math.round(freeMemoryBytes / 1024 / 1024);
const platform = os.platform();
const architecture = os.arch();
const hostname = os.hostname();
const uptimeSec = Math.round(os.uptime());
const disks = await si.fsSize();
const storage = disks.map(disk => ({
mount: disk.mount,
total: Math.round(disk.size / 1024 / 1024 / 1024), // Convert to GB
used: Math.round(disk.used / 1024 / 1024 / 1024), // Convert to GB
available: Math.round(disk.available / 1024 / 1024 / 1024) // Convert to GB
}));
return {
cpu: cpu,
totalMemoryMb: totalMemoryMb,
freeMemoryMb: freeMemoryMb,
platform: platform,
architecture: architecture,
hostname: hostname,
uptimeSec: uptimeSec,
storage: storage
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment