Created
November 12, 2018 15:26
-
-
Save farskid/af2abb2980b75eca4fe38a9c4538a310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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