- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js - os.loadavg() Method
The os module of Node.js provides a bunch of operating system-related utility methods and properties.
The Node.js os.loadavg() method will return an array containing load averages of 1, 5, and 15 minutes. The load average is a measure of system activity and it will be calculated by the operating system and it'll be displayed as a fractional number.
The load average is a Unix-specific concept. When os.loadavg() method is compiled on the windows operating system it will always return the resultant array as [0, 0, 0].
Syntax
Following is the example of the Node.js os.loadavg() method −
os.loadavg()
Parameters
This method does not accept any parameters.
Return value
This method will return a number array containing the 1, 5, and 15 minute load averages of the system activity.
Example
In the following example, we are trying to execute the Node.js os.loadavg() method on WINDOWS operating system.
const os = require('os'); console.log(os.loadavg());
Output
[ 1.70947265625, 3.12890625, 3.38720703125 ]
Note − To get the accurate result, better execute the above code in local.
If we compile and run the above program, the os.loadavg() method will return a number array as [0, 0, 0] because, it is compiled on windows operating system and on windows the return value is always [0, 0, 0].
[ 0, 0, 0 ]
Example
In the example below, we are trying to log the 1, 5, and 15 minute load averages of the system activity on WINDOWS operating system.
const os = require('os'); var load_avg = os.loadavg(); function func() { console.log("The average Load of 1 minute in windows is :" + load_avg[0]); console.log("The average Load of 5 minute in windows is :" + load_avg[1]); console.log("The average Load of 15 minute in windows is :" + load_avg[2]); } func();
Output
The average Load of 1 minute in windows is :1.87060546875 The average Load of 5 minute in windows is :2.28466796875 The average Load of 15 minute in windows is :2.71630859375
Note − To get the accurate result, better execute the above code in local.
After executing the above program on windows operating system, the os.loadavg() method logged the 1, 5, and 15 minute load averages of the system activity as 0, 0, and 0.
The average Load of 1 minute in windows is :0 The average Load of 5 minute in windows is :0 The average Load of 15 minute in windows is :0
Example
In the example below, we are trying to execute the os.loadavg() method on LINUX operating system.
const os = require('os'); console.log(os.loadavg());
Output
If we compile and run the above program on LINUX operating system, the os.loadavg() method will return a number array of some fractional numbers as seen in the below output.
[ 2.0380859375, 2.5341796875, 3.0341796875 ]
Example
In the example below, we are trying to log the 1, 5, and 15-minute load averages of the system activity on LINUX operating system.
const os = require('os'); var load_avg = os.loadavg(); function func() { console.log("The average Load of 1 minute in LINUX is :" + load_avg[0]); console.log("The average Load of 5 minute in LINUX is :" + load_avg[1]); console.log("The average Load of 15 minute in LINUX is :" + load_avg[2]); } func();
Output
The average Load of 1 minute in LINUX is :1.73193359375 The average Load of 5 minute in LINUX is :2.43408203125 The average Load of 15 minute in LINUX is :2.9912109375
To Continue Learning Please Login
Login with Google