Skip to content

Commit ef70132

Browse files
committed
fix: avoid error when zfs array is not configured
fix: include zfs arcstats in export list Signed-off-by: Hudson Gerwing <grownuphudson@gmail.com>
1 parent 10d412a commit ef70132

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

psutil/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184
# functions
185185
"pid_exists", "pids", "process_iter", "wait_procs", # proc
186-
"virtual_memory", "swap_memory", # memory
186+
"virtual_memory", "swap_memory", "apply_zfs_arcstats", # memory
187187
"cpu_times", "cpu_percent", "cpu_times_percent", "cpu_count", # cpu
188188
"cpu_stats", # "cpu_freq", "getloadavg"
189189
"net_io_counters", "net_connections", "net_if_addrs", # network

psutil/_pslinux.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,20 @@ def apply_zfs_arcstats(vm_stats: svmem):
608608
input virtual memory call results"""
609609
mems = {}
610610

611-
with open_binary('%s/spl/kstat/zfs/arcstats' % get_procfs_path()) as f:
612-
for line in f:
613-
fields = line.split()
614-
try:
615-
mems[fields[0]] = int(fields[2])
616-
except ValueError:
617-
# Not a key: value line
618-
continue
619-
620611
try:
612+
with open_binary('%s/spl/kstat/zfs/arcstats' % get_procfs_path()) as f:
613+
for line in f:
614+
fields = line.split()
615+
try:
616+
mems[fields[0]] = int(fields[2])
617+
except ValueError:
618+
# Not a key: value line
619+
continue
620+
621621
zfs_min = mems[b'c_min']
622622
zfs_size = mems[b'size']
623-
except KeyError:
624-
msg = ("ZFS ARC memory stats couldn't be determined, "
623+
except (KeyError, FileNotFoundError):
624+
msg = ("ZFS ARC memory is not configured on this device, "
625625
"no modification made to virtual memory stats")
626626
warnings.warn(msg, RuntimeWarning, stacklevel=2)
627627
zfs_min = zfs_size = 0

0 commit comments

Comments
 (0)