diff options
Diffstat (limited to 'jobs/sys_network_rate.py')
-rwxr-xr-x | jobs/sys_network_rate.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/jobs/sys_network_rate.py b/jobs/sys_network_rate.py new file mode 100755 index 0000000..3a5cc71 --- /dev/null +++ b/jobs/sys_network_rate.py @@ -0,0 +1,22 @@ +from collections import namedtuple + +Data = namedtuple('Data', ['hostname', 'device', 'entry', 'value']) +temp = {} + +def job(device, entry, intervals): + global temp + f = open('/sys/class/net/' + device + '/statistics/' + entry, 'r') + value = f.read() + ivalue = int(value.replace("\n", "")) + f.close() + + return_value = [] + if entry in temp: + rate = (ivalue - temp[entry]) / intervals # bytes/s + if rate > 0: + # prevent counter overflows + return_value = [Data('laer.2.localnet.cc', device, entry, rate)] + + temp[entry] = ivalue + + return return_value |