Skip to content

Incorrect measurements if sampleMs !== 1000 #1

Open
@EisFrei

Description

@EisFrei

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions