traffic 1.0 KB

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/perl
  2. # traffic -- summarize bandwidth usage
  3. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the
  17. # Free Software Foundation, Inc.
  18. # 59 Temple Place, Suite 330
  19. # Boston, MA 02111-1307 USA
  20. #
  21. # $Id: traffic,v 1.2 2006/09/01 11:14:34 as Exp $</p>'
  22. while (<STDIN>) {
  23. # 304 responses have - as bytes
  24. $bytes += $1 if m/\[.*?\] ".*?" \d+ (\d+)/;
  25. }
  26. printf "%d %dK %.1fM %.2fG\n", $bytes, $bytes/1024, $bytes/1024000, $bytes/1024000000;