Skip to content

Commit

Permalink
fix: avoid error when zfs array is not configured
Browse files Browse the repository at this point in the history
fix: include zfs arcstats in export list

Signed-off-by: Hudson Gerwing <grownuphudson@gmail.com>
  • Loading branch information
hewdoe committed Mar 25, 2024
1 parent 10d412a commit ef70132
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

# functions
"pid_exists", "pids", "process_iter", "wait_procs", # proc
"virtual_memory", "swap_memory", # memory
"virtual_memory", "swap_memory", "apply_zfs_arcstats", # memory
"cpu_times", "cpu_percent", "cpu_times_percent", "cpu_count", # cpu
"cpu_stats", # "cpu_freq", "getloadavg"
"net_io_counters", "net_connections", "net_if_addrs", # network
Expand Down
22 changes: 11 additions & 11 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,20 +608,20 @@ def apply_zfs_arcstats(vm_stats: svmem):
input virtual memory call results"""
mems = {}

with open_binary('%s/spl/kstat/zfs/arcstats' % get_procfs_path()) as f:
for line in f:
fields = line.split()
try:
mems[fields[0]] = int(fields[2])
except ValueError:
# Not a key: value line
continue

try:
with open_binary('%s/spl/kstat/zfs/arcstats' % get_procfs_path()) as f:
for line in f:
fields = line.split()
try:
mems[fields[0]] = int(fields[2])
except ValueError:
# Not a key: value line
continue

zfs_min = mems[b'c_min']
zfs_size = mems[b'size']
except KeyError:
msg = ("ZFS ARC memory stats couldn't be determined, "
except (KeyError, FileNotFoundError):
msg = ("ZFS ARC memory is not configured on this device, "
"no modification made to virtual memory stats")
warnings.warn(msg, RuntimeWarning, stacklevel=2)
zfs_min = zfs_size = 0
Expand Down

0 comments on commit ef70132

Please sign in to comment.