Skip to content

Commit 65f2ae8

Browse files
committed
Remove temporary file for the Class Net and fix the net unit
1 parent 2d734b5 commit 65f2ae8

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

library/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from library.log import logger
88

9+
PNIC_BEFORE = ""
910

1011
def load_yaml(configfile):
1112
with open(configfile, "r") as stream:

library/stats.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -576,27 +576,21 @@ def stats():
576576
class Net:
577577
@staticmethod
578578
def stats():
579-
pnic_before_file = "/tmp/pnic_before"
580-
581579
pnic_after = psutil.net_io_counters(pernic=True)
582-
if os.path.exists(pnic_before_file) and os.path.isfile(pnic_before_file):
583-
with open(pnic_before_file, "rb") as file:
584-
pnic_before = pickle.load(file)
580+
if config.PNIC_BEFORE:
581+
pnic_before = config.PNIC_BEFORE
585582
else:
586583
pnic_before = pnic_after
587584

588-
with open(pnic_before_file, "wb") as file:
589-
pickle.dump(pnic_after, file)
590-
591585
if WLO_CARD in pnic_after:
592586
upload_wlo = pnic_after[WLO_CARD].bytes_sent - pnic_before[WLO_CARD].bytes_sent
593-
upload_wlo_text = f"{bytes2human(upload_wlo)}B/s"
587+
upload_wlo_text = f"{bytes2human(upload_wlo)}/s"
594588
uploaded_wlo = pnic_after[WLO_CARD].bytes_sent
595-
uploaded_wlo_text = f"{bytes2human(uploaded_wlo)}B/s"
589+
uploaded_wlo_text = f"{bytes2human(uploaded_wlo)}"
596590
download_wlo = pnic_after[WLO_CARD].bytes_recv - pnic_before[WLO_CARD].bytes_recv
597-
download_wlo_text = f"{bytes2human(download_wlo)}B/s"
591+
download_wlo_text = f"{bytes2human(download_wlo)}/s"
598592
downloaded_wlo = pnic_after[WLO_CARD].bytes_recv
599-
downloaded_wlo_text = f"{bytes2human(downloaded_wlo)}B/s"
593+
downloaded_wlo_text = f"{bytes2human(downloaded_wlo)}"
600594
else:
601595
upload_wlo_text = f"N/A"
602596
uploaded_wlo_text = f"N/A"
@@ -605,13 +599,13 @@ def stats():
605599

606600
if ETH_CARD in pnic_after:
607601
upload_eth = pnic_after[ETH_CARD].bytes_sent - pnic_before[ETH_CARD].bytes_sent
608-
upload_eth_text = f"{bytes2human(upload_eth)}B/s"
602+
upload_eth_text = f"{bytes2human(upload_eth)}/s"
609603
uploaded_eth = pnic_after[ETH_CARD].bytes_sent
610-
uploaded_eth_text = f"{bytes2human(uploaded_eth)}B/s"
604+
uploaded_eth_text = f"{bytes2human(uploaded_eth)}"
611605
download_eth = pnic_after[ETH_CARD].bytes_recv - pnic_before[ETH_CARD].bytes_recv
612-
download_eth_text = f"{bytes2human(download_eth)}B/s"
606+
download_eth_text = f"{bytes2human(download_eth)}/s"
613607
downloaded_eth = pnic_after[ETH_CARD].bytes_recv
614-
downloaded_eth_text = f"{bytes2human(downloaded_eth)}B/s"
608+
downloaded_eth_text = f"{bytes2human(downloaded_eth)}"
615609
else:
616610
upload_eth_text = f"N/A"
617611
uploaded_eth_text = f"N/A"
@@ -729,6 +723,8 @@ def stats():
729723
THEME_DATA['STATS']['NET']['ETH']['DOWNLOADED']['TEXT'].get("BACKGROUND_IMAGE",
730724
None))
731725
)
726+
727+
config.PNIC_BEFORE = psutil.net_io_counters(pernic=True)
732728

733729

734730
class Date:

0 commit comments

Comments
 (0)