Socket
Socket
Sign inDemoInstall

net-stat

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    net-stat

Network statistics


Version published
Weekly downloads
77
decreased by-20.62%
Maintainers
1
Install size
13.3 kB
Created
Weekly downloads
 

Readme

Source

net-stat

  ______  _______ _______ _______ _______ _______ _______
 |   _  \|   _   |       |   _   |       |   _   |       |
 |.  |   |.  1___|.|   | |   1___|.|   | |.  1   |.|   | |
 |.  |   |.  __)_`-|.  |-|____   `-|.  |-|.  _   `-|.  |-'
 |:  |   |:  1   | |:  | |:  1   | |:  | |:  |   | |:  |
 |::.|   |::.. . | |::.| |::.. . | |::.| |::.|:. | |::.|
 `--- ---`-------' `---' `-------' `---' `--- ---' `---'

Note: This repo can be found on npm here: net-stat

Note: This repo can be found on github here: node-net-stat

Caveat: Works by parsing /proc/net/dev, so will only work on nix OS.

Install

npm install net-stat

Examples

Require the module:

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

By default totalRx() returns total received bytes for interface lo:

var totalrx = netStat.totalRx();
console.log(totalrx);

Return total received GiB on interface eth0, see docs below for accepted values of units and iface:

var totalrx = netStat.totalRx({ iface: 'eth0', units: 'GiB' });
console.log(totalrx);

Display the transmitted KiB per second of eth0 over the next 2000ms:

setInterval(function() {
  netStat.usageTx({
    iface: 'eth0',
    units: 'KiB',
    sampleMs: 2000,
  }, function(kbps) {
    console.log('Transmitted ' + kbps + ' kb/s');
  });
}, 2500);

Get all fields available from /proc/net/dev, useful for finding accepted values of iface:

var allStats = netStat.raw();
console.log(allStats);

totalRx([opts])

Returns a number representing the number of units received on iface.

OptionTypeDefaultExplanation
optsObjectsee belowOptions object, specify what you need, the defaults will be filled in
opts.ifaceString'lo'The name of the interface to be used. See the raw() function for a list of interfaces.
opts.unitsString'bytes'The units of the returned value, can be one of bytes, KiB, MiB or GiB.

totalTx([opts])

Returns a number representing the number of units transmitted on iface.

OptionTypeDefaultExplanation
optsObjectsee belowOptions object, specify what you need, the defaults will be filled in
opts.ifaceString'lo'The name of the interface to be used. See the raw() function for a list of interfaces.
opts.unitsString'bytes'The units of the returned value, can be one of bytes, KiB, MiB or GiB.

usageRx([opts,] cb)

Async function which returns data, the usage received per second in units on iface over sampleMs

OptionTypeDefaultExplanation
optsObjectsee belowOptions object, specify what you need, the defaults will be filled in
opts.ifaceString'lo'The name of the interface to be used. See the raw() function for a list of interfaces.
opts.unitsString'bytes'The units of the returned value, can be one of bytes, KiB, MiB or GiB.
opts.sampleMsNumber1000The number of milliseconds to take a usage sample over.
cbFunctionnoneA callback function with signature cb(data) where data is the usage received per second in units on iface over sampleMs.

usageTx([opts,] cb)

Async function which returns data, the usage transmitted per second in units on iface over sampleMs

OptionTypeDefaultExplanation
optsObjectsee belowOptions object, specify what you need, the defaults will be filled in
opts.ifaceString'lo'The name of the interface to be used. See the raw() function for a list of interfaces.
opts.unitsString'bytes'The units of the returned value, can be one of bytes, KiB, MiB or GiB.
opts.sampleMsNumber1000The number of milliseconds to take a usage sample over.
cbFunctionnoneA callback function with signature cb(data) where data is the usage transmitted per second in units on iface over sampleMs.

raw()

Returns an object representing the data in /proc/net/dev.

{
  eth0: {
    bytes: { receive: '2085477580', transmit: '187911353' },
    packets: { receive: '1782197', transmit: '1353772' },
    errs: { receive: '0', transmit: '0' },
    drop: { receive: '42', transmit: '0' },
    fifo: { receive: '0', transmit: '0' },
    frame: { receive: '0' },
    compressed: { receive: '0', transmit: '0' },
    multicast: { receive: '7923' },
    colls: { transmit: '0' },
    carrier: { transmit: '0' }
  },
  lo: {
    bytes: { receive: '52720310', transmit: '52720310' },
    packets: { receive: '443962', transmit: '443962' },
    errs: { receive: '0', transmit: '0' },
    drop: { receive: '0', transmit: '0' },
    fifo: { receive: '0', transmit: '0' },
    frame: { receive: '0' },
    compressed: { receive: '0', transmit: '0' },
    multicast: { receive: '0' },
    colls: { transmit: '0' },
    carrier: { transmit: '0' }
  },
}

Contributing

Just send a PR, or create an issue if you are not sure.

Areas ripe for contribution:

  • testing
  • cross compatability for windows and darwin/osx
  • performance
  • bugs

Other Stat Modules

Note: net-stat, disk-stat, mem-stat only work on nix platforms.

License

MIT

Keywords

FAQs

Last updated on 30 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc