npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

topparser

v1.0.3

Published

Parse linux TOP command output to JSON format.

Downloads

25

Readme

Parse linux / Unix "top" command to json format

Parse unix TOP command raw output to JSON format using node.js without external dependencies. On Windows PC you can use WSL (windows subsystem for linux).

Test

Just run:

//navigate to module folder and run
npm run start
or
node example.js

Install

//require node > v.12.0.0
npm install topparser

Donate

Usage

var topparser=require("topparser")


    //start topparser
    topparser.start()

    //then data is available
    topparser.on("data",data=>{
        console.log(JSON.stringify(data,0,2))
    })

    //if some error happens
    topparser.on("error",error=>{
        console.log(error)
    })

    //if topparser exit
    topparser.on("close",code=>{
        console.log(code)
    })

    //kill topparser after 10 seconds, for example
    setTimeout(()=>{
        topparser.stop()
    },10000)

Options


var options={
              pid_limit:10,//limit number of included pids in list (default: unlimited)
              pid_filter:(proc)=>{return proc.user=="root"?proc:null},// filtering the pid list (for example: include only pid with user == root) (default: null)
              pid_sort:(a,b)=>{return a.cpu-b.cpu},// sorting pid list by cpu usage (default)
            }


    //start topparser, with options (optional): pid_limit, pid_sort, pid_filter
    topparser.start(options)
    ....

JSON output:

{
  "top": {
    "time": "01:50:41",
    "up_hours": "2:21",
    "users": "0",
    "load_average": [
      "0.52",
      "0.58",
      "0.59"
    ]
  },
  "tasks": {
    "total": "17",
    "running": "1",
    "sleeping": "16",
    "stopped": "0",
    "zombie": "0"
  },
  "cpu": {
    "us": "17.5",
    "sy": "4.7",
    "ni": "0.0",
    "id": "77.5",
    "wa": "0.0",
    "hi": "0.4",
    "si": "0.0",
    "st": "0.0"
  },
  "mem": {
    "total": "33411872",
    "used": "16217872",
    "free": "16964648",
    "buff_cache": "229352"
  },
  "swap": {
    "used": "186300",
    "avail_mem": "17060268"
  },
  "processes": [
    [
      {
        "pid": "1",
        "user": "root",
        "pr": "20",
        "ni": "0",
        "virt": "8892",
        "res": "312",
        "shr": "272",
        "s": "S",
        "cpu": "0.0",
        "mem": "0.0",
        "time": "0:00.07",
        "command": "init"
      },
      {
        "pid": "8",
        "user": "root",
        "pr": "20",
        "ni": "0",
        "virt": "8908",
        "res": "232",
        "shr": "180",
        "s": "S",
        "cpu": "0.0",
        "mem": "0.0",
        "time": "0:00.01",
        "command": "init"
      }
    ]
  ]
}