index.js
function _parseProcNetDev() {
  var buf = fs.readFileSync('/proc/net/dev');
  var lines = buf.toString().trim().split('\n');
  var sections = lines.shift().split('|');
  var columns = lines.shift().trim().split('|');

  var s;
  var l;
  var c;
  var p = 0;
  var map = {};
  var keys = [];
  for (var i = 0; i < sections.length; ++i) {
    s = sections[i].trim();
    l = sections[i].length;
    c = columns[i].trim().split(/\s+/g);
    while (c.length) {
      map[keys.length] = s;
      keys.push(c.shift());
    }
    p += s.length + 1;
  }

  var retObj = {};

  lines.forEach(function(l) {
    l = l.trim().split(/\s+/g);
    var o = {};
    var iface;
    for (var i = 0; i < l.length; ++i) {
      var s = map[i];

      //case for the Interface
      if (s.indexOf('-') === s.length - 1) {
        iface = l[i].substr(0, l[i].length - 1);

      //case for everything else
      } else {
        if (!o[keys[i]]) {
          o[keys[i].toLowerCase()] = {};
        }
        o[keys[i].toLowerCase()][s.toLowerCase()] = l[i];
      }
    }
    retObj[iface] = o;
  });

  return retObj;
}
function _parseProcNetDev() {
  var buf = fs.readFileSync('/proc/net/dev');
  var lines = buf.toString().trim().split('\n');
  var sections = lines.shift().split('|');
  var columns = lines.shift().trim().split('|');

  var s;
  var l;
  var c;
  var p = 0;
  var map = {};
  var keys = [];
  for (var i = 0; i < sections.length; ++i) {
    s = sections[i].trim();
    l = sections[i].length;
    c = columns[i].trim().split(/\s+/g);
    while (c.length) {
      map[keys.length] = s;
      keys.push(c.shift());
    }
    p += s.length + 1;
  }

  var retObj = {};

  lines.forEach(function(l) {
    l = l.trim().split(/\s+/g);
    var o = {};
    var iface;
    for (var i = 0; i < l.length; ++i) {
      var s = map[i];

      //case for the Interface
      if (s.indexOf('-') === s.length - 1) {
        iface = l[i].substr(0, l[i].length - 1);

      //case for everything else
      } else {
        if (!o[keys[i]]) {
          o[keys[i].toLowerCase()] = {};
        }
        o[keys[i].toLowerCase()][s.toLowerCase()] = l[i];
      }
    }
    retObj[iface] = o;
  });

  return retObj;
}
function _parseProcNetDev ( ) { var buf = fs . readFileSync ( '/proc/net/dev' ) ; var lines = buf . toString ( ) . trim ( ) . split ( '\n' ) ; var sections = lines . shift ( ) . split ( '|' ) ; var columns = lines . shift ( ) . trim ( ) . split ( '|' ) ; var s ; var l ; var c ; var p = 0 ; var map = { } ; var keys = [ ] ; for ( var i = 0 ; i < sections . length ; ++ i ) { s = sections [ i ] . trim ( ) ; l = sections [ i ] . length ; c = columns [ i ] . trim ( ) . split ( / \s+ / g ) ; while ( c . length ) { map [ keys . length ] = s ; keys . push ( c . shift ( ) ) ; } p += s . length + 1 ; } var retObj = { } ; lines . forEach ( function ( l ) { l = l . trim ( ) . split ( / \s+ / g ) ; var o = { } ; var iface ; for ( var i = 0 ; i < l . length ; ++ i ) { var s = map [ i ] ; //case for the Interface if ( s . indexOf ( '-' ) === s . length - 1 ) { iface = l [ i ] . substr ( 0 , l [ i ] . length - 1 ) ; //case for everything else } else { if ( ! o [ keys [ i ] ] ) { o [ keys [ i ] . toLowerCase ( ) ] = { } ; } o [ keys [ i ] . toLowerCase ( ) ] [ s . toLowerCase ( ) ] = l [ i ] ; } } retObj [ iface ] = o ; } ) ; return retObj ; }
NOTE: borrowed/modifed from `https://github.com/soldair/node-procfs-stats/blob/feca2a940805b31f9e7d5c0bd07c4e3f8d3d5303/index.js#L343` TODO: more cleaning, rename the one char variables to something more expressive
NOTE : borrowed / modifed from https : // github . com / soldair / node - procfs - stats / blob / feca2a940805b31f9e7d5c0bd07c4e3f8d3d5303 / index . js#L343 TODO : more cleaning rename the one char variables to something more expressive