SunilWang / node-os-utils

OS Utils - An operating system utility library.
https://www.npmjs.com/package/node-os-utils
MIT License
126 stars 19 forks source link

fixed linuxFreeMemory typo, added check for MemAvailable #12

Closed sabattle closed 4 years ago

sabattle commented 4 years ago

I currently am using WSL, which doesn't have the MemAvailable metric in /proc/meminfo. Additionally, MemAvailable was added in the Linux 3.14 kernel, so this PR should help those with older kernels installed. This is what is contained in the memInfo object after calling mem.info():

{
  totalMemMb: 16303.29,
  usedMemMb: NaN,
  freeMemMb: NaN,
  freeMemPercentage: NaN
}

I have added a check to see if that property exists, and if not it will be calculated. After adding the fix, here is the new contents of memInfo on my machine, which seems to be fairly accurate:

{
  totalMemMb: 16303.29,
  usedMemMb: 9113.89,
  freeMemMb: 7189.4,
  freeMemPercentage: 44.1
}

I also fixed a typo, renaming linuxFreeMemroy to linuxFreeMemory.

SunilWang commented 4 years ago

Thank you for your PR. @sabattle

SunilWang commented 4 years ago

done!

https://www.npmjs.com/package/node-os-utils

npm install node-os-utils@1.3.1