From 69c220cda3d8c0a95327630f5752dad36cb82261 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 17 Jul 2018 12:34:04 +0200 Subject: Squashed commit --- jobs/sys_network_rate.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 jobs/sys_network_rate.py (limited to 'jobs/sys_network_rate.py') 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 -- cgit v1.2.1