this package will parse the output from the linux top command into JSON object
it supports any number of columns and fields
there are 2 ways to use this package
- API
- CLI
npm i linux-top-parser -S
const { parseTopInfo, topInfoTransform } = require("linux-top-parser");
// normal string parsing
const topInfo = parseTopInfo(TOP_INFO_STRING);
// or using transform stream
createReadStream(TOP_FILE_PATH)
.pipe(topInfoTransform({
stringify: true
}))
.pipe(process.stdout)
There are 2 code examples shown in the example folder on how to use this package
the CLI can be pipe from the output of top
command
top -b | npx linux-top-parser
or you can use the JSON processor CLI ( jq ) to process the stream
top -b | npx linux-top-parser | jq ".[0].summaryDisplay"
linux-top-parser [options]
Options:
-V, --version output the version number
-s, --summary output summary display only (default: false)
-p, --prettify output top info with indentation and color (default: false)
-f, --filter output process that has > 0% of CPU usage only (default: false)
-h, --help display help for command