NodeJS - Cpu Usage

1,222 views
Skip to first unread message

Marcel Araujo

unread,
Apr 27, 2012, 1:29:47 PM4/27/12
to nodejs
Hy guys

How can I use the module OS return of method cpus() to transform in
percentage? They're in milliseconds! Some one knows that?

Thanks

Ben Noordhuis

unread,
Apr 27, 2012, 1:38:17 PM4/27/12
to nod...@googlegroups.com
On Fri, Apr 27, 2012 at 19:29, Marcel Araujo <cece...@gmail.com> wrote:
> How can I use the module OS return of method cpus() to transform in
> percentage? They're in milliseconds! Some one knows that?

Percentage of what? os.uptime() * 1000?

Marcel Araujo

unread,
Apr 27, 2012, 1:47:57 PM4/27/12
to nod...@googlegroups.com
Percentage of cpu.sys, cpu.user and cpu.idle!

2012/4/27 Ben Noordhuis <in...@bnoordhuis.nl>

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--

Marcel Araujo
Analista de Sistemas
Administrador CodeIgniter.com.br
Desenvolvedor PHP/CodeIgniter/Zend/JavaScript/ExtJS/jQuery
Linux User #490101

http://www.twitter.com/marcelaraujo
http://www.marcelaraujo.com.br
http://br.linkedin.com/in/marcelaraujo


Marcel Araujo

unread,
Apr 27, 2012, 1:49:50 PM4/27/12
to nod...@googlegroups.com
I got this when I use module OS and method cpus()

[ { model: 'Intel(R) Core(TM)2 Duo CPU     E7500  @ 2.93GHz',
    speed: 2938,
    times: { user: 383080, nice: 0, sys: 705670, idle: 158793840, irq: 0 } },
  { model: 'Intel(R) Core(TM)2 Duo CPU     E7500  @ 2.93GHz',
    speed: 2938,
    times: { user: 225890, nice: 0, sys: 441210, idle: 159216960, irq: 0 } } ]

I wanna transform times.user, times.sys and times.idle in percentage value!



2012/4/27 Marcel Araujo <cece...@gmail.com>

Mark Hahn

unread,
Apr 27, 2012, 1:57:45 PM4/27/12
to nod...@googlegroups.com
If idle means all the time your process was not active then just add the three together and use them as the base.

If not, then record the time when the process starts and then divide reported times by time since process started.  This should work no matter what idle means.

Mark Hahn

unread,
Apr 27, 2012, 1:59:58 PM4/27/12
to nod...@googlegroups.com
Actually, I just discovered os.uptime().  Use that as the base.

Marcel Araujo

unread,
Apr 27, 2012, 2:09:19 PM4/27/12
to nod...@googlegroups.com

Marcel Araujo

unread,
Apr 27, 2012, 2:51:26 PM4/27/12
to nod...@googlegroups.com
No, this doesn't work for me. Idle is always 100%.

I'll try on Windows to sure that is corrected.

2012/4/27 Marcel Araujo <cece...@gmail.com>
Reply all
Reply to author
Forward
0 new messages