From 1c0bc41c360ead1c438a5da2813c90396f8eacfd Mon Sep 17 00:00:00 2001 From: BHa <18441954+BrHal@users.noreply.github.com> Date: Sun, 3 Jan 2021 20:36:24 +0100 Subject: [PATCH 1/2] Add new boolean option "use_fstab". --- bpytop.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/bpytop.py b/bpytop.py index 8c8434f..0966807 100755 --- a/bpytop.py +++ b/bpytop.py @@ -163,6 +163,9 @@ swap_disk=$swap_disk #* If mem box should be split to also show disks info. show_disks=$show_disks +#* Read disks list from /etc/fstab. +use_fstab=$use_fstab + #* Set fixed values for network graphs, default "10M" = 10 Mibibytes, possible units "K", "M", "G", append with "bit" for bits instead of bytes, i.e "100mbit" net_download="$net_download" net_upload="$net_upload" @@ -356,7 +359,7 @@ class Config: '''Holds all config variables and functions for loading from and saving to disk''' keys: List[str] = ["color_theme", "update_ms", "proc_sorting", "proc_reversed", "proc_tree", "check_temp", "draw_clock", "background_update", "custom_cpu_name", "proc_colors", "proc_gradient", "proc_per_core", "proc_mem_bytes", "disks_filter", "update_check", "log_level", "mem_graphs", "show_swap", - "swap_disk", "show_disks", "net_download", "net_upload", "net_auto", "net_color_fixed", "show_init", "theme_background", + "swap_disk", "show_disks", "use_fstab", "net_download", "net_upload", "net_auto", "net_color_fixed", "show_init", "theme_background", "net_sync", "show_battery", "tree_depth", "cpu_sensor", "show_coretemp", "proc_update_mult", "shown_boxes"] conf_dict: Dict[str, Union[str, int, bool]] = {} color_theme: str = "Default" @@ -384,6 +387,7 @@ class Config: show_swap: bool = True swap_disk: bool = True show_disks: bool = True + use_fstab: bool = False net_download: str = "10M" net_upload: str = "10M" net_color_fixed: bool = False @@ -392,7 +396,7 @@ class Config: show_battery: bool = True show_init: bool = True log_level: str = "WARNING" - + warnings: List[str] = [] info: List[str] = [] @@ -3050,6 +3054,7 @@ class MemCollector(Collector): io_string: str u_percent: int disk_list: List[str] = [] + fstab_filter: List[str] = [] cls.disks = {} if CONFIG.disks_filter: @@ -3069,10 +3074,22 @@ class MemCollector(Collector): errlog.error(f'Caused by outdated psutil version.') errlog.exception(f'{e}') io_counters = None + try: + with open('/etc/fstab','r') as fstab: + for line in fstab: + line = line.strip() + if line and not line.startswith('#'): + mount_data = (line.split()) + if mount_data[2].lower() != "swap": + fstab_filter += [mount_data[1]] + except IOError: + pass - for disk in psutil.disk_partitions(): + for disk in psutil.disk_partitions(CONFIG.use_fstab): disk_io = None io_string = "" + if CONFIG.use_fstab and disk.mountpoint not in fstab_filter: + continue disk_name = disk.mountpoint.rsplit('/', 1)[-1] if not disk.mountpoint == "/" else "root" #while disk_name in disk_list: disk_name += "_" disk_list += [disk_name] @@ -4053,6 +4070,10 @@ class Menu: 'Split memory box to also show disks.', '', 'True or False.'], + "use_fstab" : [ + 'Read disks list from /etc/fstab.', + '', + 'True or False.'], "net_download" : [ 'Fixed network graph download value.', '', From 6fd08c83614bc98725a57aeb6899914b0e680b34 Mon Sep 17 00:00:00 2001 From: BHa <18441954+BrHal@users.noreply.github.com> Date: Mon, 4 Jan 2021 17:43:48 +0100 Subject: [PATCH 2/2] use_fstab optimizations. Better handling of non-exiting /etc/fstab filter status debug logging --- bpytop.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/bpytop.py b/bpytop.py index 0966807..acadea5 100755 --- a/bpytop.py +++ b/bpytop.py @@ -2990,6 +2990,8 @@ class MemCollector(Collector): old_disks: List[str] = [] + fstab_filter: List[str] = [] + excludes: List[str] = ["squashfs", "nullfs"] if SYSTEM == "BSD": excludes += ["devfs", "tmpfs", "procfs", "linprocfs", "gvfs", "fusefs"] @@ -3054,7 +3056,6 @@ class MemCollector(Collector): io_string: str u_percent: int disk_list: List[str] = [] - fstab_filter: List[str] = [] cls.disks = {} if CONFIG.disks_filter: @@ -3074,21 +3075,28 @@ class MemCollector(Collector): errlog.error(f'Caused by outdated psutil version.') errlog.exception(f'{e}') io_counters = None - try: - with open('/etc/fstab','r') as fstab: - for line in fstab: - line = line.strip() - if line and not line.startswith('#'): - mount_data = (line.split()) - if mount_data[2].lower() != "swap": - fstab_filter += [mount_data[1]] - except IOError: - pass + + if CONFIG.use_fstab and not cls.fstab_filter: + try: + with open('/etc/fstab','r') as fstab: + for line in fstab: + line = line.strip() + if line and not line.startswith('#'): + mount_data = (line.split()) + if mount_data[2].lower() != "swap": + cls.fstab_filter += [mount_data[1]] + errlog.debug(f'new fstab_filter set : {cls.fstab_filter}') + except IOError: + CONFIG.use_fstab = False + errlog.debug(f'Error reading fstab, use_fstab flag reset to {CONFIG.use_fstab}') + if not CONFIG.use_fstab and cls.fstab_filter: + cls.fstab_filter = [] + errlog.debug(f'use_fstab flag has been turned to {CONFIG.use_fstab}, fstab_filter cleared') for disk in psutil.disk_partitions(CONFIG.use_fstab): disk_io = None io_string = "" - if CONFIG.use_fstab and disk.mountpoint not in fstab_filter: + if CONFIG.use_fstab and disk.mountpoint not in cls.fstab_filter: continue disk_name = disk.mountpoint.rsplit('/', 1)[-1] if not disk.mountpoint == "/" else "root" #while disk_name in disk_list: disk_name += "_"