peerStats 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. /* -*- Mode:Js */
  3. /* vim: set expandtab ts=4 sw=4: */
  4. /*
  5. * You may redistribute this program and/or modify it under the terms of
  6. * the GNU General Public License as published by the Free Software Foundation,
  7. * either version 3 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
  18. var PublicToIp6 = require('./lib/publicToIp6');
  19. Cjdns.connectAsAnon(function (cjdns) {
  20. var again = function (i) {
  21. cjdns.InterfaceController_peerStats(i, function (err, ret) {
  22. if (err) { throw err; }
  23. ret.peers.forEach(function (peer) {
  24. p = peer['addr'] + ' ' + peer['state'] +
  25. ' in ' + peer['recvKbps'] + 'kb/s' +
  26. ' out ' + peer['sendKbps'] + 'kb/s';
  27. if (Number(peer['duplicates']) !== 0) {
  28. p += ' ' + ' DUP ' + peer['duplicates'];
  29. }
  30. if (Number(peer['lostPackets']) !== 0) {
  31. p += ' ' + ' LOS ' + peer['lostPackets'];
  32. }
  33. if (Number(peer['receivedOutOfRange']) !== 0) {
  34. p += ' ' + ' OOR ' + peer['receivedOutOfRange'];
  35. }
  36. if (typeof(peer.user) === 'string') {
  37. p += ' "' + peer['user'] + '"';
  38. }
  39. console.log(p);
  40. });
  41. if (typeof(ret.more) !== 'undefined') {
  42. again(i+1);
  43. } else {
  44. cjdns.disconnect();
  45. }
  46. });
  47. };
  48. again(0);
  49. });