Skip to content

Instantly share code, notes, and snippets.

@farskid
Created November 12, 2018 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farskid/af2abb2980b75eca4fe38a9c4538a310 to your computer and use it in GitHub Desktop.
Save farskid/af2abb2980b75eca4fe38a9c4538a310 to your computer and use it in GitHub Desktop.
const os = require("os");
// install this custom module!!
const babar = require("babar");
function calculateFreeMemPercentage() {
return Number(((os.freemem * 100) / os.totalmem).toFixed(2));
}
function printChart(points) {
console.log(
babar(points, {
caption: "Memory usage chart",
color: "magenta",
width: 40,
height: 40,
yFractions: 0.1,
xFractions: 0.1
})
);
}
// Run
(function main() {
const points = [];
let i = 0;
setInterval(() => {
// Gets a 2d Array with x axis values as counter and y axis values as memory usage percentage
points.push([i++, calculateFreeMemPercentage()]);
points.length > 1 &&
(function fragment() {
console.clear();
printChart(points);
})();
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment