Nstats

A fast and compact way to get all your network and process stats for your node application

View the Project on GitHub Phara0h/nstats

Nstats

A fast and compact way to get all your network and process stats for your node application. Websocket and express compatible!

Installation

$ npm install nstats

Quick Start

// ws is a websocket server (ws.js)
var stats = require('nstats')(ws.clients);

//use it with express
app.use(stats.express);

//display the stats!
console.log(stats.data); // non-stringifyed
console.log(stats.toJson()) // stringifyed

Properties

stats.data

The stats.data object is a JavaScript object containing all the stats.

{
  uptime: 0,
  totalMemory: 0,
  totalOnlineUsers: 0,
  avgWriteKBs: 0,
  avgReadKBs: 0,
  avgPacketsSecond: 0,
  bytesWritten: 0,
  totalBytesWritten: 0,
  totalMBytesWritten: 0,
  bytesRead: 0,
  totalBytesRead: 0,
  totalMBytesRead: 0,
  writeKBS: 0,
  readKBS: 0,
  totalPackets: 0
}

feel free to add your own stats you want to keep track off too!

stats.data['foo'] = "some dank stat";

stats.interval

A time in milliseconds on when the stats will refresh and calculate.

stats.interval = 5000; // default is 1 second

Set this to 0 if you do not want it to loop.

Methods

stats.addWeb()

A method to add network usage for http requests not done with express.

http.get("http://google.com", function(res) {
    res.on('end', function() {
      stats.addWeb(res);
    });
});

Since its not express, it does not know about it.


stats.calc()

A method to allow you to manually trigger when the stats are computed.

optional call back can be passed to let you know its done.

stats.calc(function(){
  //its done!
  console.log(stats.data);
});