Arrow keys: ← previous · → next 19 of 35
@nodedk/monitor
0.1.5 experimental

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(): runs free -m and returns memory and swap rows under mem and swap, with fields such as total, used, and free.
  • hd(): runs df -h and returns an array of filesystem records. Fields include filesystem, size, used, avail, capacity, iused, ifree, %iused, and mountedon.
  • cpu(): runs top -n 1 -b and returns its summary fields plus a list of 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