fixed: si.network_speed()
This commit is contained in:
parent
803cd90163
commit
af3118e15c
46
README.md
46
README.md
@ -1,16 +1,20 @@
|
||||
# systeminformation
|
||||
|
||||
Simple system and OS information library for node.js
|
||||
Simple system and OS information library for [node.js][nodejs-url]
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![MIT license][license-img]][license-url]
|
||||
[![deps status][daviddm-img]][daviddm-url]
|
||||
|
||||
## Using systeminformation
|
||||
### --- Working already on Version 2 - stay tuned ---
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
$ npm install systeminformation
|
||||
$ npm install systeminformation --save
|
||||
```
|
||||
|
||||
### Usage
|
||||
@ -92,7 +96,7 @@ This library is splitted in several sections:
|
||||
| - [0].ip6 | X | X | ip6 address |
|
||||
| si.network_speed('eth1') | X | | current network speed of given interface |
|
||||
| - operstate | X | | up / down |
|
||||
| - rx_sec | X | | received bytes / second |
|
||||
| - rx_sec | X | X | received bytes / second |
|
||||
| - tx_sec | X | X | transferred bytes per second |
|
||||
| si.currentload() | X | X | CPU-Load in % |
|
||||
| si.fullload() | X | X | CPU-full load since bootup in % |
|
||||
@ -127,6 +131,9 @@ si.network_speed('eth1', function(data) {
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 1.0.7 | 2015-11-27 | fixed: si.network_speed() |
|
||||
| 1.0.6 | 2015-09-17 | fixed: si.users() |
|
||||
| 1.0.5 | 2015-09-14 | updated dependencies |
|
||||
| 1.0.4 | 2015-07-18 | updated docs |
|
||||
| 1.0.3 | 2015-07-18 | bugfix cpu cores |
|
||||
| 1.0.2 | 2015-07-18 | bugfix cpu_currentspeed, cpu_temperature |
|
||||
@ -144,19 +151,23 @@ If you have ideas or comments, please do not hesitate to contact me.
|
||||
Happy monitoring!
|
||||
|
||||
Sincerely,
|
||||
Sebastian Hildebrandt
|
||||
http://www.plus-innovations.com
|
||||
|
||||
Sebastian Hildebrandt, [+innovations](http://www.plus-innovations.com)
|
||||
|
||||
#### Credits
|
||||
## Credits
|
||||
|
||||
Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebrandt)
|
||||
|
||||
#### License
|
||||
#### Contributers
|
||||
|
||||
>The MIT License (MIT)
|
||||
Guillaume Legrain [glegrain](https://github.com/glegrain)
|
||||
Riccardo Novaglia [richy24](https://github.com/richy24)
|
||||
|
||||
## License [![MIT license][license-img]][license-url]
|
||||
|
||||
>The [`MIT`][license-url] License (MIT)
|
||||
>
|
||||
>Copyright (c) 2015 +innovations.
|
||||
>Copyright © 2015 Sebastian Hildebrandt, [+innovations](http://www.plus-innovations.com).
|
||||
>
|
||||
>Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
>of this software and associated documentation files (the "Software"), to deal
|
||||
@ -179,7 +190,16 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
|
||||
>Further details see [LICENSE](LICENSE) file.
|
||||
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/systeminformation.svg
|
||||
[npm-image]: https://img.shields.io/npm/v/systeminformation.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/systeminformation
|
||||
[downloads-image]: https://img.shields.io/npm/dm/systeminformation.svg
|
||||
[downloads-url]: https://npmjs.org/package/systeminformation
|
||||
[downloads-image]: https://img.shields.io/npm/dm/systeminformation.svg?style=flat-square
|
||||
[downloads-url]: https://npmjs.org/package/systeminformation
|
||||
|
||||
[license-url]: https://github.com/sebhildebrandt/systeminformation/blob/master/LICENSE
|
||||
[license-img]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
|
||||
[npmjs-license]: https://img.shields.io/npm/l/systeminformation.svg?style=flat-square
|
||||
|
||||
[nodejs-url]: https://nodejs.org/en/
|
||||
|
||||
[daviddm-url]: https://david-dm.org/sebhildebrandt/systeminformation
|
||||
[daviddm-img]: https://img.shields.io/david/sebhildebrandt/systeminformation.svg?style=flat-square
|
||||
|
||||
103
lib/index.js
103
lib/index.js
@ -6,6 +6,8 @@
|
||||
// Copyright: (c) 2014 - 2015
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Contributors: Guillaume Legrain (https://github.com/glegrain)
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
//
|
||||
@ -19,36 +21,36 @@
|
||||
// 6. Processes
|
||||
// 7. Users
|
||||
// 8. Internet
|
||||
//
|
||||
//
|
||||
// ==================================================================================
|
||||
//
|
||||
// Installation
|
||||
// --------------------------------
|
||||
// At the time of writing, this library is dependent on the "request" module,
|
||||
// which needs to be installed seperately. I created a npm package.json file,
|
||||
// At the time of writing, this library is dependent on the "request" module,
|
||||
// which needs to be installed seperately. I created a npm package.json file,
|
||||
// to be able to install it easily:
|
||||
//
|
||||
// npm install
|
||||
//
|
||||
//
|
||||
// ==================================================================================
|
||||
//
|
||||
// Usage
|
||||
// --------------------------------
|
||||
// All functions are asynchronous functions. Here a small example how to use them:
|
||||
//
|
||||
//
|
||||
// var sysinfo = require('./sysinfo.js');
|
||||
//
|
||||
//
|
||||
// sysinfo.cpu(function(data) {
|
||||
// console.log('CPU-Information:');
|
||||
// console.log(data);
|
||||
// })
|
||||
//
|
||||
//
|
||||
// ==================================================================================
|
||||
//
|
||||
// Comments
|
||||
// --------------------------------
|
||||
// This library is work in progress. It is quite "fresh" - means, there might be a
|
||||
// lot of inconsoistencies or even bugs. I was only able to test it on some
|
||||
// This library is work in progress. It is quite "fresh" - means, there might be a
|
||||
// lot of inconsoistencies or even bugs. I was only able to test it on some
|
||||
// Debian and Ubuntu distributions as well as OSX (Maveriks).
|
||||
//
|
||||
// Comments, suggestions & reports are very wellcome!
|
||||
@ -158,7 +160,7 @@ exports.osinfo =function(callback) {
|
||||
if (line.indexOf('ProductName') != -1) {
|
||||
result.distro = line.split(':')[1].trim();
|
||||
result.logofile = getLogoFile(result.distro);
|
||||
}
|
||||
}
|
||||
if (line.indexOf('ProductVersion') != -1) result.release = line.split(':')[1].trim();
|
||||
})
|
||||
callback(result);
|
||||
@ -261,7 +263,7 @@ exports.cpu_currentspeed = function(callback) {
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// CPU - temperature
|
||||
// CPU - temperature
|
||||
// if sensors are installed
|
||||
|
||||
exports.cpu_temperature = function(callback) {
|
||||
@ -336,11 +338,11 @@ exports.mem = function(callback) {
|
||||
result.swapfree = parseInt(mem[3]);
|
||||
result.swapused = parseInt(mem[2]);
|
||||
|
||||
callback(result);
|
||||
callback(result);
|
||||
} else {
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
exec("vm_stat | grep 'Pages active'", function(error, stdout, stderr) {
|
||||
if (!error) {
|
||||
@ -348,11 +350,11 @@ exports.mem = function(callback) {
|
||||
|
||||
result.active = parseInt(lines[0].split(':')[1]) * 4096;
|
||||
result.buffcache = result.used - result.active;
|
||||
callback(result);
|
||||
callback(result);
|
||||
} else {
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,7 +383,7 @@ exports.fs_size = function(callback) {
|
||||
}
|
||||
})
|
||||
callback(data)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
@ -464,7 +466,7 @@ exports.network_interfaces = function(callback) {
|
||||
++alias;
|
||||
//result.push({iface : dev+(alias?':'+alias:''), ip4 : ip4, ip6 : ip6})
|
||||
result.push({iface : dev, ip4 : ip4, ip6 : ip6})
|
||||
}
|
||||
}
|
||||
callback(result);
|
||||
}
|
||||
|
||||
@ -485,7 +487,7 @@ exports.network_speed = function(interface, callback) {
|
||||
var operstate = lines[0].trim();
|
||||
var rx = parseInt(lines[1]);
|
||||
var tx = parseInt(lines[2]);
|
||||
|
||||
|
||||
if (tmp_network["iface"]) {
|
||||
var ms = Date.now() - tmp_network["iface"].ms;
|
||||
rx_sec = (rx - tmp_network["iface"].rx) / (ms / 1000);
|
||||
@ -507,7 +509,41 @@ exports.network_speed = function(interface, callback) {
|
||||
}
|
||||
});
|
||||
} else callback(null);
|
||||
} else callback(null);
|
||||
} else {
|
||||
var cmd = "netstat -ibI " + iface;
|
||||
exec(cmd, function(error, stdout, stderr) {
|
||||
if (!error) {
|
||||
var lines = stdout.toString().split('\n');
|
||||
// if there is less than 2 lines, no information for this interface was found
|
||||
if (lines.length > 1) {
|
||||
// skip header line
|
||||
// TODO: operstate
|
||||
// use the second line because it is tied to the NIC instead of the ipv4 or ipv6 address
|
||||
var stats = lines[1].replace(/ +/g, " ").split(' ');
|
||||
var rx = parseInt(stats[6]);
|
||||
var tx = parseInt(stats[9]);
|
||||
|
||||
if (tmp_network["iface"]) {
|
||||
var ms = Date.now() - tmp_network["iface"].ms;
|
||||
rx_sec = (rx - tmp_network["iface"].rx) / (ms / 1000);
|
||||
tx_sec = (tx - tmp_network["iface"].tx) / (ms / 1000);
|
||||
} else {
|
||||
rx_sec = 0;
|
||||
tx_sec = 0;
|
||||
tmp_network["iface"] = {};
|
||||
}
|
||||
tmp_network["iface"].rx = rx;
|
||||
tmp_network["iface"].tx = tx;
|
||||
tmp_network["iface"].ms = Date.now();
|
||||
|
||||
callback({
|
||||
rx_sec : rx_sec,
|
||||
tx_sec : tx_sec
|
||||
});
|
||||
}
|
||||
} else callback(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -529,7 +565,7 @@ function getload(callback) {
|
||||
lines.pop()
|
||||
result.currentload = ((lines.reduce(function(pv, cv) { return pv + parseFloat(cv.trim()); }, 0)) / tmp_cores),
|
||||
callback(result)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.currentload = function(callback) {
|
||||
@ -543,7 +579,7 @@ exports.currentload = function(callback) {
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// PS - full load
|
||||
// PS - full load
|
||||
// since bootup
|
||||
|
||||
function getfullload(callback) {
|
||||
@ -576,7 +612,7 @@ exports.fullload = function(callback) {
|
||||
|
||||
// --------------------------
|
||||
// PS - services
|
||||
// pass a koma separated string with services to check (mysql, apache, postgresql, ...)
|
||||
// pass a koma separated string with services to check (mysql, apache, postgresql, ...)
|
||||
// this function gives an array back, if the services are running.
|
||||
|
||||
exports.services = function(srv, callback) {
|
||||
@ -596,7 +632,7 @@ exports.services = function(srv, callback) {
|
||||
})
|
||||
})
|
||||
callback(data)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
@ -633,18 +669,18 @@ exports.processes = function(callback) {
|
||||
}
|
||||
})
|
||||
}
|
||||
callback(result);
|
||||
callback(result);
|
||||
})
|
||||
}
|
||||
} else {
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// PS - process load
|
||||
// get detailed information about a certain process
|
||||
// PS - process load
|
||||
// get detailed information about a certain process
|
||||
// (PID, CPU-Usage %, Mem-Usage %)
|
||||
|
||||
exports.processload = function(proc, callback) {
|
||||
@ -665,10 +701,10 @@ exports.processload = function(proc, callback) {
|
||||
'cpu' : parseFloat(data[2].replace(',', '.')),
|
||||
'mem' : parseFloat(data[3].replace(',', '.'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -680,14 +716,13 @@ exports.processload = function(proc, callback) {
|
||||
// array of users online
|
||||
|
||||
exports.users = function(callback) {
|
||||
result.users = [];
|
||||
result = [];
|
||||
exec("users", function(error, stdout, stderr) {
|
||||
result = [];
|
||||
if (!error) {
|
||||
result.users = stdout.toString().replace(/ +/g, " ").replace(/\n+/g, " ").trim().split(' ').filter(function(e) {return e.trim() !== ''});
|
||||
result = stdout.toString().replace(/ +/g, " ").replace(/\n+/g, " ").trim().split(' ').filter(function(e) {return e.trim() !== ''});
|
||||
}
|
||||
callback(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ -695,7 +730,7 @@ exports.users = function(callback) {
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
// check if external site is available
|
||||
// check if external site is available
|
||||
|
||||
exports.checksite = function(url, callback) {
|
||||
var t = Date.now();
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "systeminformation",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"description": "Simple system and OS information library",
|
||||
"license": "MIT",
|
||||
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
|
||||
"homepage": "https://github.com/sebhilderandt/systeminformation",
|
||||
"main": "./lib/index.js",
|
||||
@ -27,7 +28,7 @@
|
||||
"url": "https://github.com/sebhilderandt/systeminformation.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": "*"
|
||||
"request": "^2.61.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user