Test Failed
Push — master ( 73a01d...ef36eb )
by Nicolas
04:43
created

glances.plugins.fs.zfs   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A zfs_enable() 0 3 1
A zfs_stats() 0 14 5
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