I have managed to do almost the same as you are asking for and i save
the traffic accumulated inside mongodb
script is easy have a look
/#!/usr/bin/env node //
///*//
// Traffic Library for reading time series data from the network and
saving it in the mongodb database//
// for further display with the charting library to be picked up //
//
// 1- mongodb driver (mongoskin)//
// 2- filesystem//
// // for now thats it (Other stuff comes in later on )//
// ////////////////////////////////////
// For now all we shall do is read data from a file //
// 1- Create a function that accepts //
// a- file name (file to read from)//
// b- regular expression (specify which fields to read //
// c- labels (eth0,up,down,...) according to fields //
// d- timestamp (time stamp to use with the database insertion)//
////
//*///
//var dbServer=require('/usr/lib/node_modules/mongoskin');//
//var fs=require('fs');//
//var db=dbServer.db('localhost:27017/traffic',{safe:true});//
//var dbCollection=db.collection('IFaces');//
///*//
//dbCollection.insert({'timeStamp':'ts','IFace':'wlan0','up':10,'down':20},function(err,result){//
// if(err) {//
// throw err//
// }//
// if(result) {//
// console.log('Added');//
// }//
//});//
//db.close();//
//*///
//// The /proc/net/dev file contains the commulative attributes for
collected data //
//var netFile='/proc/net/dev'//
//var nowTime=Date.now();//
//var netFileRegex=/([a-zA-Z0-9]+):.*/mg;//
//var
netFileRegex2=/([a-zA-Z0-9]+):\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)/m;//
//var netFileData='';//
//// open the file //
//var netFileStream=fs.createReadStream(netFile,{encoding:'ascii',});//
//
//netFileStream.on('data',function(data){//
// netFileData+=data;//
//});//
//netFileStream.on('end',function(err){//
// if(err) {//
// throw err;//
// }else{//
// var netMatches=netFileData.match(netFileRegex);//
// netMatches.forEach(function(i,v){//
// var netDevMatch=i.match(netFileRegex2);//
// var netDevTxRxObject={//
// 'TS' : nowTime,//
// 'DEV' : netDevMatch[1],//
// 'RXb' : netDevMatch[2],//
// 'RXp' : netDevMatch[3],//
// 'TXb' : netDevMatch[10],//
// 'TXp' : netDevMatch[11]//
// }//
//
// //netDevMatch[1];//
//// console.log(JSON.stringify(netDevTxRxObject));//
//dbCollection.insert(netDevTxRxObject,function(err,result){//
// if(err) {//
// throw err;//
// }//
// });//
// });//
// }//
// db.close();//
//});/
Much Regards
Faysal Banna
Meteorological Services
Rafic Harriri International Airport
Beirut - Lebanon
Mob: +961-3-258043
On 08/25/2013 04:34 PM, Ashutosh Das wrote:
Is there any way to extract network interface data ( exmample : RX
bytes ) using node ? there is
os.networkInterfaces() but that does not show full information of
network interfaces .
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.