A simple way to monitor node memory usage.
Image above shows logging values of rss and heapTotal to the console in bar graph form.
- CSV - Monitor.createFormatterCSV()
- JSON - Monitor.createFormatterJSON()
- Bar Graph - Monitor.createFormatterBarGraph(maxValueMB)
- Console - Monitor.createLoggerConsole(fieldsToLog)
- File - Monitor.createLoggerFile(fieldsToLog, filePath)
The constructor accepts an options object which currently has just one field: separator
, specifying which separator to use when joining fields. Default separator value is a comma - ,
.
// bring in the module
const Monitor = require('/path/to/monitor');
// create an instance
const monitor = new Monitor();
// specify the fields you want to track
const fields = ['rss', 'heapTotal'];
// create a formatter
const maxSizeMB = 20;
const formatter = monitor.createFormatterBarGraph(maxSizeMB);
// create a logger
const logger = monitor.createLoggerConsole(fields);
// create the tracker
const tracker = monitor.createTracker(fields, formatter, logger);
// start the tracker
const interval = 1000;
const intervalId = monitor.startMonitor(tracker, interval);
// stop the tracker
clearInterval(intervalId);
When using the file logger you can monitor the file change in real time by running tail -f fileName