aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2020-05-31 16:25:39 +0200
committerPapoteur <papoteur@mageia.org>2020-05-31 16:41:09 +0200
commit0e866b3ea99621cd5d58ca3bf04be897ae1e53b7 (patch)
tree51de29ceb01999cdbf5297fcf2c5fbbba779a655 /src
parent6d68f4e1285552fb671a0ed2a2183e93fa1adda4 (diff)
downloadnet_monitor-0e866b3ea99621cd5d58ca3bf04be897ae1e53b7.tar
net_monitor-0e866b3ea99621cd5d58ca3bf04be897ae1e53b7.tar.gz
net_monitor-0e866b3ea99621cd5d58ca3bf04be897ae1e53b7.tar.bz2
net_monitor-0e866b3ea99621cd5d58ca3bf04be897ae1e53b7.tar.xz
net_monitor-0e866b3ea99621cd5d58ca3bf04be897ae1e53b7.zip
Restore test on statistic enabled (mga#25417)
Diffstat (limited to 'src')
-rw-r--r--src/monitor.py14
-rwxr-xr-xsrc/net_monitor6
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)