aboutsummaryrefslogtreecommitdiffstats
path: root/src/monitor.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/monitor.py')
-rw-r--r--src/monitor.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/monitor.py b/src/monitor.py
index 3198b78..6f0704a 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -10,6 +10,8 @@ import struct
import traceback
import array
import time
+import json
+from subprocess import Popen, PIPE
# native library implements a few bits
from . import _native
@@ -247,11 +249,17 @@ class Monitor:
def has_network_accounting(self, iface):
"""Checks if network accounting was enabled on interface"""
- try:
- os.stat("/var/lib/vnstat/%s" % iface)
- return True
+ try:
+ pr = Popen(("vnstat --json -i %s" % (iface)).split(), stdout=PIPE)
+ data, _ = pr.communicate()
+ data = data.decode('utf-8')
+ if data[0] == "{":
+ data_tab = json.loads(data)
+ if data_tab['interfaces'][0]['name'] == iface:
+ return True
except:
return False
+ return False
def get_traffic(self, iface, net=None):
"""Get traffic information"""