- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用程式模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - os.loadavg() 方法
Node.js 的os 模組提供了一組與作業系統相關的實用程式方法和屬性。
Node.js os.loadavg() 方法將返回一個數組,其中包含 1 分鐘、5 分鐘和 15 分鐘的平均負載。平均負載是衡量系統活動的指標,它由作業系統計算,並顯示為小數。
平均負載是 Unix 系統特有的概念。當os.loadavg() 方法在 Windows 作業系統上編譯時,它將始終返回結果陣列 [0, 0, 0]。
語法
以下是Node.js os.loadavg() 方法的示例:
os.loadavg()
引數
此方法不接受任何引數。
返回值
此方法將返回一個數字陣列,其中包含系統活動 1 分鐘、5 分鐘和 15 分鐘的平均負載。
示例
在下面的示例中,我們嘗試在 WINDOWS 作業系統上執行Node.js os.loadavg() 方法。
const os = require('os');
console.log(os.loadavg());
輸出
[ 1.70947265625, 3.12890625, 3.38720703125 ]
注意:要獲得準確的結果,最好在本地執行上述程式碼。
如果我們編譯並執行上述程式,os.loadavg() 方法將返回一個數字陣列 [0, 0, 0],因為它是Windows作業系統上編譯的,在Windows上返回值始終為 [0, 0, 0]。
[ 0, 0, 0 ]
示例
在下面的示例中,我們嘗試記錄 WINDOWS 作業系統上系統活動的 1 分鐘、5 分鐘和 15 分鐘平均負載。
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();
輸出
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
注意:要獲得準確的結果,最好在本地執行上述程式碼。
在 Windows 作業系統上執行上述程式後,os.loadavg() 方法將系統活動的 1 分鐘、5 分鐘和 15 分鐘平均負載記錄為 0、0 和 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
示例
在下面的示例中,我們嘗試在 LINUX 作業系統上執行 os.loadavg() 方法。
const os = require('os');
console.log(os.loadavg());
輸出
如果我們在 LINUX 作業系統上編譯並執行上述程式,os.loadavg() 方法將返回一些小數的數字陣列,如下面的輸出所示。
[ 2.0380859375, 2.5341796875, 3.0341796875 ]
示例
在下面的示例中,我們嘗試記錄 LINUX 作業系統上系統活動的 1 分鐘、5 分鐘和 15 分鐘平均負載。
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();
輸出
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
