Open chinarui-na opened 6 days ago
1s call once, this is the nodejs code
const si = require('systeminformation');
function formatSpeed(speed) {
if (speed >= 1024) {
return `${(speed / 1024).toFixed(0)}MB/s`;
} else {
return `${speed.toFixed(0)}kB/s`;
}
}
function getNetworkInfo() {
return new Promise(async (resolve, reject) => {
try {
const [networkStats, networkInterfaces] = await Promise.all([
si.networkStats(),
si.networkInterfaces()
]);
const interfaceTypes = new Map(networkInterfaces.map(iface => [iface.iface, iface.type]));
const formattedStats = networkStats.map(stat => {
const downloadSpeed = stat.rx_sec / 1024; // Convert to kB/s
const uploadSpeed = stat.tx_sec / 1024; // Convert to kB/s
const type = interfaceTypes.get(stat.iface);
return {
interface: stat.iface,
networkType: type === 'wireless' ? 'Wi-Fi' : (type === 'wired' ? 'Wired' : 'Other'),
download_kBps: Math.ceil(downloadSpeed),
upload_kBps: Math.ceil(uploadSpeed),
download_str: formatSpeed(downloadSpeed),
upload_str: formatSpeed(uploadSpeed)
};
});
resolve(formattedStats);
} catch (error) {
reject(error);
}
});
}
getNetworkInfo()
Sometimes it seems, sometimes it doesn't
i use networkStats to get
rx_bytes
andtx_bytes
in windows, Windows11 is fine, Windows10 these values are always 0logs: