npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

net-stat-promise

v0.0.3

Published

Network statistics

Downloads

8

Readme

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.

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ opts | Object | see below | Options object, specify what you need, the defaults will be filled in opts.iface | String | 'lo' | The name of the interface to be used. See the raw() function for a list of interfaces. opts.units | String | '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.

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ opts | Object | see below | Options object, specify what you need, the defaults will be filled in opts.iface | String | 'lo' | The name of the interface to be used. See the raw() function for a list of interfaces. opts.units | String | '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

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ opts | Object | see below | Options object, specify what you need, the defaults will be filled in opts.iface | String | 'lo' | The name of the interface to be used. See the raw() function for a list of interfaces. opts.units | String | 'bytes' | The units of the returned value, can be one of bytes, KiB, MiB or GiB. opts.sampleMs | Number | 1000 | The number of milliseconds to take a usage sample over. cb | Function | none | A 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

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ opts | Object | see below | Options object, specify what you need, the defaults will be filled in opts.iface | String | 'lo' | The name of the interface to be used. See the raw() function for a list of interfaces. opts.units | String | 'bytes' | The units of the returned value, can be one of bytes, KiB, MiB or GiB. opts.sampleMs | Number | 1000 | The number of milliseconds to take a usage sample over. cb | Function | none | A 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