Created
January 13, 2012 17:21
-
-
Save bobuk/1607615 to your computer and use it in GitHub Desktop.
forswan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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