summaryrefslogtreecommitdiff
path: root/jobs/sys_network_rate.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2018-07-17 12:34:04 +0200
committerYves Fischer <yvesf-git@xapek.org>2018-07-17 12:49:49 +0200
commit69c220cda3d8c0a95327630f5752dad36cb82261 (patch)
treefad9fbe78cf717f4dd17b8e9d996ab9a54b7d3e2 /jobs/sys_network_rate.py
downloaddatasources-69c220cda3d8c0a95327630f5752dad36cb82261.tar.gz
datasources-69c220cda3d8c0a95327630f5752dad36cb82261.zip
Squashed commit
Diffstat (limited to 'jobs/sys_network_rate.py')
-rwxr-xr-xjobs/sys_network_rate.py22
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