require('os').freemem() is totally offset?

572 views
Skip to first unread message

Tom

unread,
Sep 24, 2011, 6:43:23 AM9/24/11
to nodejs
I'm trying to figure out how much memory is used by my system, like
so:

var os = require('os'),
total = os.totalmem(),
usage = total - os.freemem(),
percentage = usage / total * 100;

Unfortunately, usage is returning 3804721152 bytes (3.5GB, 95%) while
Ubuntu's System Monitor tells me I am only using 2.2GB (60.1%).

Is freemem bugged, or should I get to my calculations differently?

Regards,
Tom

Ben Noordhuis

unread,
Sep 24, 2011, 11:42:23 AM9/24/11
to nod...@googlegroups.com

os.totalmem() and os.freemem() report the number of *physical* pages.
I don't know what System Monitor reports but it's probably something
else.

mscdex

unread,
Sep 24, 2011, 2:12:44 PM9/24/11
to nodejs
On Sep 24, 6:43 am, Tom <tommed...@gmail.com> wrote:
> Is freemem bugged, or should I get to my calculations differently?

Works fine for me on Ubuntu (10.04). Try comparing it to the numbers
found by running something like `top`.
Reply all
Reply to author
Forward
0 new messages