Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect measurements if sampleMs !== 1000 #1

Open
EisFrei opened this issue Jan 12, 2018 · 0 comments
Open

Incorrect measurements if sampleMs !== 1000 #1

EisFrei opened this issue Jan 12, 2018 · 0 comments

Comments

@EisFrei
Copy link

EisFrei commented Jan 12, 2018

This is most likely cause by dividing through the square of diffSeconds in lines
https://github.com/jub3i/node-net-stat/blob/master/index.js#L75
https://github.com/jub3i/node-net-stat/blob/master/index.js#L110

When running this test, the results differ by a factor of 5.

var netStat = require('net-stat');

setInterval(function() {
  netStat.usageRx({
    iface: 'eth0',
    units: 'KiB',
    sampleMs: 5000,
  }, function(kbps) {
    console.log('sample 5000 Received ' + kbps + ' kb/s');
  });
  netStat.usageRx({
    iface: 'eth0',
    units: 'KiB',
    sampleMs: 1000,
  }, function(kbps) {
    console.log('sample 1000 Received ' + kbps + ' kb/s');
  });
}, 5500);

sample 1000 Received 1252.6483312645523 kb/s
sample 5000 Received 250.9826604677602 kb/s
sample 1000 Received 1253.4795914675788 kb/s
sample 5000 Received 250.77318140432646 kb/s
sample 1000 Received 1244.4695225893756 kb/s
sample 5000 Received 250.59871011495855 kb/s
sample 1000 Received 1252.6885511615906 kb/s
sample 5000 Received 251.13570570135803 kb/s

I suggest changing the calculation of totalPerSecond to
var totalPerSecond = total / (diffSeconds * 1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant