完整的程序链接下载

util

建立一个util,计算使用

var utils = {}
utils.humanFileSize = function(bytes, isDecimal) {isDecimal = (typeof isDecimal !== 'undefined') ? isDecimal : false;if (bytes == 0) {return "0.00 B";}var base = isDecimal ? 1000 : 1024;var e = Math.floor(Math.log(bytes) / Math.log(base));return (bytes / Math.pow(base, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + (isDecimal || e == 0 ? '' : 'i') + 'B';
}utils.colors = ['magenta', 'cyan', 'blue', 'yellow', 'green', 'red'];module.exports = utils;

进程

所有进程
/*** author :钱波* 抓取所有进程* */var si = require('systeminformation'),utils = require('./utils');
var hashmap = require('hashmap')
//var colors = utils.colors;class proc_class {//var hashmapsay(callback) {si.processes().then(data => {//var pu = [];this.hashmap_pid = new hashmap();this.array = [];var data1 = data.list.map(p => {var value = {pid: p.pid,cmd: p.name, //.slice(0,10),cpuuse: p.pcpu.toFixed(1),memuse: p.pmem.toFixed(1)}this.hashmap_pid.set('"'+p.pid+'"', value)this.array.push(value);//pu.push()})if (callback != null) {// console.log("...start to print...",this.hashmap_pid);callback(this.array);}}).catch(error => console.error(error));}getpidname(id) {//console.log("hashmap", this.hashmap_pid);//console.log("want to find", id);let test = this.hashmap_pid.get(id);//console.log("test is ", test);if (test != null) {return test.cmd;//console.log("find it",test);}return null;     //return this.hashmap_pid;}}## 网络
module.exports = new proc_class();
/** unit test
//function call(data) {
//    console.log(data);
//}
//var proc = new proc_class();
//proc.say(call);
*/
var si = require('systeminformation'),utils = require('./utils');
class net_class {updateData(data,callback) {//console.log(data);var rx_sec = Math.max(0, data['rx_sec']);var tx_sec = Math.max(0, data['tx_sec']);//this.netData[0].shift();//this.netData[0].push(rx_sec);//this.netData[1].shift();//this.netData[1].push(tx_sec);//rx_label = 'Receiving:      ' +//    utils.humanFileSize(rx_sec) +//    '/s \nTotal received: ' +//    utils.humanFileSize(data['rx_bytes']);//tx_label = 'Transferring:      ' +//    utils.humanFileSize(tx_sec) +//    '/s \nTotal transferred: ' +//    utils.humanFileSize(data['tx_bytes']);if (callback != null) {callback({rxsec: utils.humanFileSize(rx_sec),txsec: utils.humanFileSize(tx_sec),total_r: utils.humanFileSize(data['rx_bytes']),total_s: utils.humanFileSize(data['tx_bytes'])})}};say(callback) {si.networkInterfaceDefault(iface => {var that = this;var updater = function () {si.networkStats(iface, data => {that.updateData(data[0],callback);});}updater();})}
}
module.exports = new net_class();

磁盘

/*** author :钱波* 抓取所有磁盘,注意不适合windows* */var si = require('systeminformation'),utils = require('./utils');//var colors = utils.colors;
class disk_class {say(callback) {si.fsSize().then(data => {var disk = data[0];//console.log(disk)data = [{use: utils.humanFileSize(disk.used, true),size: utils.humanFileSize(disk.size, true),percent: disk.use / 100}];if (callback != null)callback(data);}).catch(error => console.error(error))}}module.exports = new disk_class();
//unit test
//function call(data) {//    console.log(data);
//}
//var disk = new disk_class();
//disk.say(call);//module.exports = Disk;

cpu

var si = require('systeminformation');var hashmap = require('hashmap')
class cpu_class{constructor() {this.cpumap = new hashmap();si.currentLoad().then(data => {data.cpus.map((cpu, i) => {var x = Array(61).fill(0);this.cpumap.set("CPU" + i+1, x);//console.log(cpu.load);})}).catch(error => console.error(error))}say(callback) {si.currentLoad().then(data => {if (callback != null)callback(data.currentload);//console.log(data.currentload);//console.log(data.avgload, data.currentload_system);data.cpus.map((cpu, i) => {let name = "CPU" + i + 1;let objArray = this.cpumap.get(name);objArray.shift();objArray.push(cpu.load);//if(i == 0)//    console.log(objArray);})}).catch(error => console.error(error))}
}module.exports = new cpu_class();//钱波 unit test
//var cpu = new cpu_class();
//cpu.say();
//setInterval(() => {//    cpu.say();
//}, 1000);//si.cpu()
//    .then(data => {//        console.log('CPU Information:');
//        console.log('- manufucturer: ' + data.manufacturer);
//        console.log('- brand: ' + data.brand);
//        console.log('- speed: ' + data.speed);
//        console.log('- cores: ' + data.cores);
//        console.log('- physical cores: ' + data.physicalCores);
//        console.log('...');
//    })
//    .catch(error => console.error(error));

内存

var si = require('systeminformation'),utils = require('./utils');var mem_Count;
var mem_Swap;class mem_class {say(callback) {si.mem().then(data => {var memPer = (100 * (1 - data.available / data.total)).toFixed();var swapPer = (100 * (1 - data.swapfree / data.swaptotal)).toFixed();swapPer = isNaN(swapPer) ? 0 : swapPer;var memTitle =utils.humanFileSize(data.total - data.available) +' of ' +utils.humanFileSize(data.total);var swapTitle =utils.humanFileSize(data.swaptotal - data.swapfree) +' of ' +utils.humanFileSize(data.swaptotal);mem_Count = {percent: memPer / 100,label: memTitle,};mem_Swap = {percent: swapPer / 100,label: swapTitle}console.log(mem_Count, mem_Swap);}).catch(error => console.error(error))}
}
module.exports = new mem_class();/*** 单元测试* @param {any} data*/
//function call(data) {//    console.log(data);
//    //console.log("test");
//}//var mem = new mem_class();
//mem.say(call);//module.exports = Mem;

所有连接

// JavaScript source code
var si = require('systeminformation');
const proc = require('./proc_0');class connection {//procdata 进程信息say(callback) {//this.callback = callback;proc.say(function (procdata) {si.networkConnections().then(data => {var pu = [];data.map((net, i) => {if (net.state == 'LISTEN') {// console.log(net);//console.log("net pid", net.pid);//console.log("get pid name",proc.getpidname('"'+net.pid+'"'));let name = proc.getpidname('"' + net.pid + '"');//console.log(name);if (name != null) {net.procname = name;}pu.push(net);//console.log(net);}});if (callback != null) {callback(pu);//console.log("pu", pu);}}).catch(error => console.error(error));});}
}module.exports = new connection();/** unit test
//包含连接信息和连接的进程名称
function callback(data) {console.log(data);
}var x = new connection();
x.say(callback);
*/

nodejs 获取内存,网络 ,连接 ,磁盘等等相关推荐

  1. android 获取当前网络,Android 获取当前网络连接的类型信息

    获取当前网络连接的类型信息 public static int getConnectedType(Context context) { if (context != null) { Connectiv ...

  2. 安卓网络连接全解:包括网络连接状态的监听、网络数据使用状态的监听、获取当前网络连接情况、启动wifi、获取当前连接wifi的网络情况、扫描wifi热点

    全栈工程师开发手册 (作者:栾鹏) 安卓教程全解 安卓网络连接情况全解:包括网络连接状态的监听.网络数据使用状态的监听.获取当前网络连接情况.启动wifi.获取当前连接wifi的网络情况.扫描wifi ...

  3. iOS获取当前网络连接状态WiFi、5G、4G、3G、2G

    iOS获取网络连接状态 通过AFNetworking获取的网络状态只有未知.无网络连接.手机自带网络.WIFI,需求是需要准确的定位到是WiFi.5G.4G.3G.2G,所以AFNetworking并 ...

  4. vb.net 教程 7-1 本地网络信息的获取 3 网络连接信息

    版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的. 通过IPGlobalProperties类可以获得网络连接的信息: 通过GetIPGlobalP ...

  5. C# 获取适配器网络连接IP地址,子网掩码,DNS,数据包等信息

    你可以大致通过cmd 输入ipconfig获得以太网的适配信息(下面只涉及以太网),其中所有列出的就是以下代码运行后将统计出来的,只是代码多得到的结果更丰富,包括 适配器接口的名称,标识符,连接状态, ...

  6. Linux 查看CPU 内存 IO使用率,linux 查看CPU内存 网络 流量 磁盘 IO

    使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...

  7. 如何查看linux网络io,linux 查看CPU内存 网络 流量 磁盘 IO

    使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...

  8. C# 获取电脑的网络连接状态

    C# 获取电脑的网络连接状态 原文:C# 获取电脑的网络连接状态 判断连网的方法介绍 1. InternetGetConnectedState 此函数获取网络状态有延时,且对网卡伤害较大 MSDN官方 ...

  9. [android] android 获取网络连接信息

    效果图: 工具类 /** * 获取网络连接信息* * 根据NetworkInfo可以知道有很多的连接方式和信息* * ① 当没有任何可用网络的时候,networkinfo为null 判断network ...

最新文章

  1. Ubuntu11.10 GNOME Shell指南
  2. redhat yum 安装 mysql_Redhat 7 下Mysql8.0.19安装配置图文详解(配合使用 centos YUM源)...
  3. 人工智能与大数据的完美结合 1
  4. 2020年中国餐饮配送机器人行业研究报告
  5. hibernate中createQuery和createSqlQuery
  6. MySQL乱码问题如何排查
  7. 马哥运维学习作业(九)
  8. 高等数学(工本)选择题
  9. Jsp简单入门与Jsp实用教程总结
  10. 九橡项目工时管理系统部署笔记
  11. aliddns ipv6_AliDDNS v2.0.0.1 - 阿里云DNS动态解析Windows客户端 支持IPv6 微信推送
  12. 怎么用美图秀秀制作证件照
  13. 20190301 小中大
  14. 读 Paxos 到 ZooKeeper ¥ 50大洋
  15. ESP8266-D1 mini-V2 认识
  16. 解决xp共享的批处理文件
  17. f1c100s kernel调试记录
  18. 如何使用Buddy构建和部署Web应用
  19. java poi jar包下载_poi.jar下载-poi.jar包下载 (3.8/3.9/3.10)版--pc6下载站
  20. 怪物猎人世界服务器小程序,坚守的猎人的最后礼物? 腾讯推出《怪物猎人世界》官方小程序...

热门文章

  1. windows命令行启动常用工具
  2. 2006年四种思路帮你创业
  3. 沃尔沃汽车警告称:半导体短缺将持续到明年
  4. 腾讯大动刀:微信试行松绑外链!用户已可打开淘宝、抖音等链接
  5. Redmi Note10系列发布时间曝光:最高搭载1亿像素主摄
  6. 抖音起诉腾讯垄断 要求停止封禁并索赔9000万元
  7. 苹果iPhone 12系列智能手机支持北斗卫星导航定位
  8. 最狠的钉子户手机!最后一款已战斗5年,还能继续...
  9. iPhone 12 Mini曝光:售价5000内、电池容量不忍看
  10. 8年前估值14.24亿的长城宽带近日被鹏博士“低价”打包出售