6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node-usage を使う

Posted at

node.js で cpu 使用率やメモリ使用率を知りたい場合に使うライブラリ

github
npm

下記のようにコードを書きます.

usage.lookup(process.pid, function(err, result) {
    console.log('cpu: ' + result.cpu + ', memory: ' + result.memory);
});

実行結果

cpu: 2.8, memory: 40714240
cpu: 0.6, memory: 40931328
cpu: 0.3, memory: 40988672
cpu: 0.8, memory: 41058304
cpu: 0.3, memory: 43454464
cpu: 0.4, memory: 43454464
cpu: 0.9, memory: 43610112

インストール

npm を使って入れられます.

$ npm install usage

ただし失敗する場合があるので自分の経験から下記を確認してみてください.

  • node-gyp が使う gyp は node-gyp に同梱されているが,システム上に gyp が入ってる場合にそちらを使って失敗するのでアンインストールするなどなんとかする.(which gyp して /usr/bin/X11/gyp が出てくるなど)
  • /usr/bin/ld: cannot find crti.o: No such file or directory というようなエラーが出る場合は LIBRARY_PATH に必要なディレクトリを追加する 参考
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?