sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.72k stars 309 forks source link

networkStats windows server 2008 I won't support it? #791

Open 617450941 opened 1 year ago

617450941 commented 1 year ago

Describe the bug The rx_sec and tx_sec properties of the objects returned by si.networkStats() are null. version "systeminformation": "^5.17.12"

To Reproduce Steps to reproduce the behavior:

Call the function getNetworkStats(). Run the code on Windows Server 2008 x64. See that the rx_sec and tx_sec properties of the objects returned by si.networkStats() are null. Current Output The rx_sec and tx_sec properties of the objects returned by si.networkStats() are null.

Expected behavior The rx_sec and tx_sec properties of the objects returned by si.networkStats() should contain valid values.

Environment

systeminformation package version: Unknown OS: Windows Server 2008 x64 Hardware: Unknown Additional context The code has been formatted below for clarity:

const si = require('systeminformation');
const {parentPort} = require("worker_threads");

async function getNetworkStats() {
    const stats = {};
    stats.rx = 0;
    stats.tx = 0;
    const netStats = await si.networkStats();

    let rxTotal = 0;
    let txTotal = 0;
    for (const iface of netStats) {
        rxTotal = iface.rx_sec + rxTotal;
        txTotal = iface.tx_sec + txTotal;
    }

    const rx = Math.round(rxTotal * 100) / 100; 
    const tx = Math.round(txTotal * 100) / 100; 

    const formattedRx = formatSizeUnits(rx);
    const formattedTx = formatSizeUnits(tx);

    stats.rx = formattedRx;
    stats.tx = formattedTx;
    stats.data = JSON.stringify(netStats);

    parentPort.postMessage({ eventName: 'network-stats', arg: stats });
}
617450941 commented 1 year ago

4.34.23 This version is normal

sebhildebrandt commented 1 year ago

@617450941 can you confirm, that the following code on your machine always returns null for rx_sec and tx_sec:

const si = require('systeminformation');
setInterval(function() {
  si.networkStats().then(data => {
    console.log(data);
  })
}, 1000)

The first call SHOULD return null but from the second call on, it should return correct values.

See also https://systeminformation.io/statsfunctions.html