fixed: si.network_speed()

This commit is contained in:
Sebastian Hildebrandt 2015-11-27 12:37:29 +01:00
parent 803cd90163
commit af3118e15c
3 changed files with 105 additions and 49 deletions

View File

@ -1,16 +1,20 @@
# systeminformation # 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 Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-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 ### Installation
```bash ```bash
$ npm install systeminformation $ npm install systeminformation --save
``` ```
### Usage ### Usage
@ -92,7 +96,7 @@ This library is splitted in several sections:
| - [0].ip6 | X | X | ip6 address | | - [0].ip6 | X | X | ip6 address |
| si.network_speed('eth1') | X | | current network speed of given interface | | si.network_speed('eth1') | X | | current network speed of given interface |
| - operstate | X | | up / down | | - 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 | | - tx_sec | X | X | transferred bytes per second |
| si.currentload() | X | X | CPU-Load in % | | si.currentload() | X | X | CPU-Load in % |
| si.fullload() | X | X | CPU-full load since bootup in % | | si.fullload() | X | X | CPU-full load since bootup in % |
@ -127,6 +131,9 @@ si.network_speed('eth1', function(data) {
| Version | Date | Comment | | 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.4 | 2015-07-18 | updated docs |
| 1.0.3 | 2015-07-18 | bugfix cpu cores | | 1.0.3 | 2015-07-18 | bugfix cpu cores |
| 1.0.2 | 2015-07-18 | bugfix cpu_currentspeed, cpu_temperature | | 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! Happy monitoring!
Sincerely, 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) 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 >Permission is hereby granted, free of charge, to any person obtaining a copy
>of this software and associated documentation files (the "Software"), to deal >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. >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 [npm-url]: https://npmjs.org/package/systeminformation
[downloads-image]: https://img.shields.io/npm/dm/systeminformation.svg [downloads-image]: https://img.shields.io/npm/dm/systeminformation.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/systeminformation [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

View File

@ -6,6 +6,8 @@
// Copyright: (c) 2014 - 2015 // Copyright: (c) 2014 - 2015
// Author: Sebastian Hildebrandt // Author: Sebastian Hildebrandt
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
// Contributors: Guillaume Legrain (https://github.com/glegrain)
// ----------------------------------------------------------------------------------
// License: MIT // License: MIT
// ================================================================================== // ==================================================================================
// //
@ -507,7 +509,41 @@ exports.network_speed = function(interface, callback) {
} }
}); });
} else callback(null); } 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);
});
}
} }
@ -680,11 +716,10 @@ exports.processload = function(proc, callback) {
// array of users online // array of users online
exports.users = function(callback) { exports.users = function(callback) {
result.users = []; result = [];
exec("users", function(error, stdout, stderr) { exec("users", function(error, stdout, stderr) {
result = [];
if (!error) { 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); callback(result);
}); });

View File

@ -1,7 +1,8 @@
{ {
"name": "systeminformation", "name": "systeminformation",
"version": "1.0.4", "version": "1.0.6",
"description": "Simple system and OS information library", "description": "Simple system and OS information library",
"license": "MIT",
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)", "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
"homepage": "https://github.com/sebhilderandt/systeminformation", "homepage": "https://github.com/sebhilderandt/systeminformation",
"main": "./lib/index.js", "main": "./lib/index.js",
@ -27,7 +28,7 @@
"url": "https://github.com/sebhilderandt/systeminformation.git" "url": "https://github.com/sebhilderandt/systeminformation.git"
}, },
"dependencies": { "dependencies": {
"request": "*" "request": "^2.61.0"
}, },
"engines": { "engines": {
"node": ">=0.10" "node": ">=0.10"