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

vitality-js

v0.0.3

Published

Easily poll the health (cpu & mem) of your server

Downloads

9

Readme

Vitality

Easily poll the health (cpu & mem) of your server

Install

$ npm install --save vitality-js

Usage

var vitality = require('vitality-js');

// Will poll every 1000ms and give you current memory usage and average cpu utilization over the last 1000ms
vitality.poll(1000, function (health) {
  console.log(health);
  /*
    {
      cpu: [
        { idle: 9500, total: 10300, percent: 7.7669902912621325 },
        { idle: 9500, total: 10100, percent: 5.940594059405946 },
        { idle: 8800, total: 10200, percent: 13.725490196078427 },
        { idle: 9300, total: 10000, percent: 6.999999999999995 }
      ],
      memory: { 
        free: 3688.92578125,
        total: 11835.86328125,
        percent: 31.16735715504487
      }
    }
  */
});

API

vitality.get()

Returns the current memory usage and cpu idle/total.

/*
{
  "cpu": [
    {
      "idle": 567355500,
      "total": 674757500
    },
    {
      "idle": 333779400,
      "total": 445816600
    },
    {
      "idle": 333948500,
      "total": 439120400
    },
    {
      "idle": 338116500,
      "total": 433799200
    }
  ],
  "memory": {
    "free": 3631.984375,
    "total": 11835.86328125,
    "percent": 30.686265029384675
  }
}
*/

vitality.difference(previous, current)

Calculates the cpu utilization between two vitality.get() calls. Also returns memory usage (latest).

/*
{
  "memory": {
    "free": 3561.45703125,
    "total": 11835.86328125,
    "percent": 30.090386705395183
  },
  "cpu": [
    {
      "idle": 52100,
      "total": 56000,
      "percent": 6.964285714285712
    },
    {
      "idle": 52100,
      "total": 56700,
      "percent": 8.112874779541446
    },
    {
      "idle": 51600,
      "total": 56500,
      "percent": 8.672566371681413
    },
    {
      "idle": 52400,
      "total": 56500,
      "percent": 7.256637168141589
    }
  ]
}
*/

vitality.poll(interval, callback)

Polls vitality.get() and returns the difference each interval to callback.

vitality.poll(1000, function (health) {
  /*
    {
      cpu: [
        { idle: 9500, total: 10300, percent: 7.7669902912621325 },
        { idle: 9500, total: 10100, percent: 5.940594059405946 },
        { idle: 8800, total: 10200, percent: 13.725490196078427 },
        { idle: 9300, total: 10000, percent: 6.999999999999995 }
      ],
      memory: { 
        free: 3688.92578125,
        total: 11835.86328125,
        percent: 31.16735715504487
      }
    }
  */
});

vitality.cpu.get()

/*
[
  {
    "idle": 570766400,
    "total": 678605700
  },
  {
    "idle": 337235700,
    "total": 449659100
  },
  {
    "idle": 337348500,
    "total": 442980100
  },
  {
    "idle": 341598300,
    "total": 437648400
  }
]
*/

vitality.cpu.difference(previous, current)

Calculates the cpu utilization between two vitality.get() calls.

/*
[
  {
    "idle": 61700,
    "total": 66400,
    "percent": 7.078313253012047
  },
  {
    "idle": 62900,
    "total": 66500,
    "percent": 5.41353383458647
  },
  {
    "idle": 60900,
    "total": 66600,
    "percent": 8.558558558558559
  },
  {
    "idle": 62600,
    "total": 66900,
    "percent": 6.427503736920781
  }
]
*/

vitality.cpu.poll(interval, callback)

Polls vitality.cpu.get() and returns the difference each interval to callback.

/*
[
  {
    "idle": 9500,
    "total": 9800,
    "percent": 3.0612244897959218
  },
  {
    "idle": 9200,
    "total": 9500,
    "percent": 3.157894736842104
  },
  {
    "idle": 9300,
    "total": 10000,
    "percent": 6.999999999999995
  },
  {
    "idle": 9600,
    "total": 9900,
    "percent": 3.0303030303030276
  }
]
*/

vitality.memory.get()

Return free/used memory.

/*
{
  free: 3644.390625,
  total: 11835.86328125,
  percent: 30.791084168514587
}
*/