peerStats 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. import sys;
  14. import math;
  15. from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
  16. from cjdnsadmin.publicToIp6 import PublicToIp6_convert;
  17. cjdns = connectWithAdminInfo();
  18. allPeers = [];
  19. i = 0;
  20. while True:
  21. ps = cjdns.InterfaceController_peerStats(i);
  22. peers = ps['peers'];
  23. allPeers += peers;
  24. if (not 'more' in ps):
  25. break;
  26. i += 1;
  27. for peer in allPeers:
  28. p = (PublicToIp6_convert(peer['publicKey']) + '\t' + peer['switchLabel'] + '\tin ' +
  29. str(peer['bytesIn']) + '\tout ' + str(peer['bytesOut']) + '\t' + peer['state'] +
  30. '\tdup ' + str(peer['duplicates']) +
  31. ' los ' + str(peer['lostPackets']) +
  32. ' oor ' + str(peer['receivedOutOfRange']));
  33. if 'user' in peer: p += '"' + peer['user'] + '"';
  34. print p;