diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/monitor.py | 14 | ||||
-rwxr-xr-x | src/net_monitor | 6 |
2 files changed, 14 insertions, 6 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""" diff --git a/src/net_monitor b/src/net_monitor index 4a8ddf9..3076c64 100755 --- a/src/net_monitor +++ b/src/net_monitor @@ -12,7 +12,7 @@ from gi.repository import Pango import gc import os -import subprocess +from subprocess import Popen, PIPE from stat import * import datetime import getopt @@ -500,7 +500,7 @@ class MonitorGui: if pretty_size == pretty_bytes: value = pretty_size + "\n" else: - value =( f"{pretty_size:<15}\n({pretty_bytes})") + value =( f"{pretty_size:<18}\n({pretty_bytes})") self.ifaces[iface][widget].set_text(str(value)) GLib.timeout_add_seconds(interval, self.update) @@ -837,7 +837,7 @@ class MonitorGui: # show summary if parameter is unknown print("Unknown parameter %s, showing summary.." % type) param="-s" - pr = subprocess.Popen(("vnstati %s -o - -i %s" % (param, iface)).split(),stdout=subprocess.PIPE) + pr = Popen(("vnstati %s -o - -i %s" % (param, iface)).split(),stdout=PIPE) data, _ = pr.communicate() loader = GdkPixbuf.PixbufLoader() loader.write(data) |