Skip to content

Instantly share code, notes, and snippets.

@bobuk
Created January 13, 2012 17:21
Show Gist options
  • Save bobuk/1607615 to your computer and use it in GitHub Desktop.
Save bobuk/1607615 to your computer and use it in GitHub Desktop.
forswan
#!/usr/bin/python
import time, sys
iface="eth0" if len(sys.argv) < 2 else sys.argv[1]
_prev_in = 0
_prev_out = 0
print "With interface: " + iface
with open("/proc/net/dev") as f:
while True:
for row in f:
[interface, lost] = row.split(":", 1) if ":" in row else [row, '']
if (interface.strip() == iface):
cnt=[int(x) for x in lost.split()]
if len(cnt) < 9:
continue
print "in: %s out: %s" % (
(cnt[1] - _prev_in),
(cnt[9] - _prev_out)
)
_prev_in=cnt[1]
_prev_out=cnt[9]
f.seek(0)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment