super-mem

1.0.7 • Public • Published

super-mem Super Mem Build Status

super-mem

Utility to manage Node.js memory

Install

npm install super-mem

API

Table of Contents

memoryUsage

Returns an object describing the memory usage of the Node.js process measured in bytes and human readable format. Note that it uses base-10.

Parameters

  • hrOnly boolean? Human readable format only, default false

Examples

{
  "rss": 42360832,
  "heapTotal": 35254272,
  "heapUsed": 16044848,
  "external": 108125,
  "rssHR": "42.4 MB",
  "heapTotalHR": "35.3 MB",
  "heapUsedHR": "16 MB",
  "externalHR": "108 kB"
}

osMemory

Returns an object describing the OS memory measured in bytes and human readable format. Note that it uses base-10.

Parameters

  • hrOnly boolean? Human readable format only, default false

Examples

{
    "totalMem": 17073917952,
    "freeMem": 11155980288,
    "totalMemHR": "17.1 GB",
    "freeMemHR": "11.2 GB"
}

sizeOf

Returns the size of the 'inputObject', measured in bytes and human readable format. Note that it uses base-10.

Parameters

  • inputObject Object Object to measure the size
  • hrOnly boolean? Human readable format only, default false

Examples

{
  "size": 20488,
  "sizeHR": "20.5 kB"
}

printMemoryStatus

Print the memory status on console

Parameters

  • decorator string? Optional string to create header and footer, default "-"

Examples

-------------------- Memory Status --------------------
 • Process memory usage:
    rss = 45.7 MB
    heapTotal = 35.8 MB
    heapUsed = 18.7 MB
 • OS memory:
    totalmem = 17.1 GB
    freemem = 11.1 GB
-------------------------------------------------------

HeapObserver

Monitors the heap memory and if the heap used exceeds the limitPerc, it notifies this to the handling functions

Parameters

  • limitPerc number Limit exceeded which the handling function is called
  • interval number? Optional, time interval between memory reading, default 10000 ms

Examples

const superMem = require('super-mem');
const heapObserver = new superMem.HeapObserver(80, 5000);
heapObserver.addHandler(function (mem, percentage) {
  console.log('HeapObserver MEM: ' + JSON.stringify(mem, null, 2));
  console.log('HeapObserver PERC: ' + parseInt(percentage) + ' %');
});
heapObserver.start();

Package Sidebar

Install

npm i super-mem

Weekly Downloads

2

Version

1.0.7

License

MIT

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • vincenzo.de.vivo