Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get/View Memory & CPU usage via NodeJS

Tags:

node.js

npm

I see there are several node packages that allow you to look up a specific process's usage, such as https://www.npmjs.com/package/usage

I am trying to get the overall sever usage/stats (CPU and Memory), not just one specific process or another. Maybe even disk space usage.

I am currently unable to find anything like this, is this possible?

like image 542
C0NFUS3D Avatar asked Apr 23 '16 20:04

C0NFUS3D


People also ask

How do I check my CPU and RAM?

In the System Properties window, on the General tab, look under Computer for details about the computer's speed and memory. Example: CPU (processor speed) = 2.93GHz. RAM (memory) = 3.25 GB of RAM.

How can I check my memory history?

Check Computer Memory Usage EasilyTo open up Resource Monitor, press Windows Key + R and type resmon into the search box. Resource Monitor will tell you exactly how much RAM is being used, what is using it, and allow you to sort the list of apps using it by several different categories.

How do I check my CPU usage for real time?

Check resource usage in Task ManagerCtrl + Shift + Escape. Ctrl + Alt + Delete, and then click Task Manager from the options presented.

How do I check Windows server memory and CPU?

Press the Windows key , type task manager, and press Enter . In the window that appears, click the Performance tab. On the Performance tab, a list of hardware devices is displayed on the left side.


Video Answer


1 Answers

The native module os can give you some memory and cpu usage statistics.

var os = require('os');  console.log(os.cpus()); console.log(os.totalmem()); console.log(os.freemem()) 

The cpus() function gives you an average, but you can calculate the current usage by using a formula and an interval, as mentioned in this answer.

There is also a package that does this for you, called os-utils.

Taken from the example on github:

var os = require('os-utils');  os.cpuUsage(function(v){     console.log( 'CPU Usage (%): ' + v ); }); 

For information about the disk you can use diskspace

like image 168
piscator Avatar answered Sep 20 '22 02:09

piscator