| Total Complexity | 6 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # |
||
| 2 | # This file is part of Glances. |
||
| 3 | # |
||
| 4 | # SPDX-FileCopyrightText: 2025 Nicolas Hennion <[email protected]> |
||
| 5 | # |
||
| 6 | # SPDX-License-Identifier: LGPL-3.0-only |
||
| 7 | # |
||
| 8 | |||
| 9 | # For the moment, thoses functions are only used in the MEM plugin (see #3979) |
||
| 10 | |||
| 11 | import os |
||
| 12 | |||
| 13 | from glances.logger import logger |
||
| 14 | |||
| 15 | |||
| 16 | def zfs_enable(zfs_stats_path='/proc/spl/kstat/zfs'): |
||
| 17 | """Check if ZFS is enabled on this system.""" |
||
| 18 | return os.path.isdir(zfs_stats_path) |
||
| 19 | |||
| 20 | |||
| 21 | def zfs_stats(zfs_stats_files=['/proc/spl/kstat/zfs/arcstats']): |
||
| 22 | """Get ZFS stats from /proc/spl/kstat/zfs files.""" |
||
| 23 | stats = {} |
||
| 24 | for zfs_stats_file in zfs_stats_files: |
||
| 25 | try: |
||
| 26 | with open(zfs_stats_file) as f: |
||
| 27 | lines = f.readlines() |
||
| 28 | namespace = os.path.basename(zfs_stats_file) |
||
| 29 | for line in lines[2:]: # Skip the first two header lines |
||
| 30 | parts = line.split() |
||
| 31 | stats[namespace + '.' + parts[0]] = int(parts[2]) |
||
| 32 | except Exception as e: |
||
| 33 | logger.error(f"Error reading ZFS stats in {zfs_stats_file}: {e}") |
||
| 34 | return stats |
||
| 35 |