1.0.7 • Published 4 years ago
super-mem v1.0.7
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, defaultfalse
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, defaultfalse
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 sizehrOnly
boolean? Human readable format only, defaultfalse
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 calledinterval
number? Optional, time interval between memory reading, default10000 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();