Created
June 3, 2016 06:51
-
-
Save sohel-rana/e60bfc2564d433c2b05c203801d803ee to your computer and use it in GitHub Desktop.
A NodeJS script to find out free memory in Mac OSX. You can also find other data like total used memory, wired memory etc.
This file contains hidden or 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
| /** | |
| * User: Sohel | |
| * Date: 6/3/16 | |
| * Time: 11:49 AM | |
| */ | |
| var sys = require('sys'); | |
| var exec = require('child_process').exec; | |
| var child; | |
| child = exec('vm_stat', function (error, stdout, stderr) { | |
| if (error === null && stderr === '') { | |
| //console.log(stdout); | |
| //remove . from the output | |
| stdout = stdout.replace(/\./g, ''); | |
| //split it by new line | |
| var pieces = stdout.split('\n'); | |
| var title = pieces.shift(); | |
| //console.log(title); | |
| var memoryData = {}; | |
| for(var i in pieces){ | |
| var splittedMemoryString = pieces[i].split(':'); | |
| memoryData[splittedMemoryString[0]] = ((splittedMemoryString[1]*4096)/1048576); //in MB | |
| } | |
| //console.log(JSON.stringify(memoryData)); | |
| //console.log(memoryData['Pages free'] , memoryData['Pages inactive']); | |
| var freeMemory = memoryData['Pages free'] + memoryData['Pages inactive']; | |
| console.log("Total Free Memory: ", freeMemory.toFixed(2), ' MB'); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment