Skip to content

sweetim/linux-top-parser

Repository files navigation

Linux TOP Parser


this package will parse the output from the linux top command into JSON object

it supports any number of columns and fields

Usage

there are 2 ways to use this package

  • API
  • CLI

API

Installation

npm i linux-top-parser -S

Code

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)

Examples

There are 2 code examples shown in the example folder on how to use this package

CLI

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"

Usage

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

Reference