Created
July 10, 2014 10:48
-
-
Save imerr/ca7da1fcf64c1667aeb2 to your computer and use it in GitHub Desktop.
network monitor
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, threading | |
import requests | |
TIMER_CYCLE = 30 | |
last = [] | |
def update(): | |
global last_total, device_speed, requestPool | |
threading.Timer(1, tick).start() | |
with open("/sys/class/net/eth0/statistics/rx_bytes", "r") as frx, open("/sys/class/net/eth0/statistics/tx_bytes", "r") as ftx: | |
rx = int(frx.read()) | |
tx = int(ftx.read()) | |
if len(last) == 2: | |
r = requests.post('http://reporturl', data = {'rx':(rx-last[0])/TIMER_CYCLE, 'tx':(tx-last[1])/TIMER_CYCLE}) | |
last = [rx, tx] | |
threading.Timer(TIMER_CYCLE, update).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment