@nodedk/monitor
monitor#
Read memory, filesystem, and CPU statistics from Linux system commands.
Requirements#
Linux with free, df, and top available on PATH. Parsing expects their
English command output.
Install#
npm i @nodedk/monitor
Usage#
var monitor = require('@nodedk/monitor')
async function main() {
var mem = await monitor.mem()
var hd = await monitor.hd()
var cpu = await monitor.cpu()
var stats = await monitor.stats()
console.log({ mem, hd, cpu })
console.log(stats.mem, stats.hd, stats.cpu)
}
main().catch(console.error)
All methods take no arguments and return Promises. Values retain the strings and units reported by the command; convert them before arithmetic.
mem(): runsfree -mand returns memory and swap rows undermemandswap, with fields such astotal,used, andfree.hd(): runsdf -hand returns an array of filesystem records. Fields includefilesystem,size,used,avail,capacity,iused,ifree,%iused, andmountedon.cpu(): runstop -n 1 -band returns its summary fields plus alistof process records. Keys are lowercased and depend on command output.stats(): runs the three methods sequentially and returns{ mem, hd, cpu }.
Created by Vidar Eldøy