add perfdata to check_zfs_zpool

This commit is contained in:
Cyberes 2024-02-23 10:57:26 -07:00
parent 2b19fd8c0d
commit c2f2b5f3db
2 changed files with 26 additions and 2 deletions

View File

@ -6,10 +6,11 @@ import sys
import zfslib as zfs import zfslib as zfs
from checker import nagios from checker import nagios, dict_to_perfdata
from checker.markdown import list_to_markdown_table from checker.markdown import list_to_markdown_table
from checker.nagios import state_to_txt from checker.nagios import state_to_txt
from checker.units import filesize from checker.units import filesize
from checker.zfs import zfs_get_free
# TODO: add perfdata # TODO: add perfdata
@ -217,7 +218,21 @@ def main():
table_data.append((device['device'], device['size'], device['alloc'], device['free'], device['frag'], table_data.append((device['device'], device['size'], device['alloc'], device['free'], device['frag'],
device['cap'], device['health'], states[device['device']])) device['cap'], device['health'], states[device['device']]))
print(list_to_markdown_table(table_data, align='center', seperator='!', borders=False)) zpool_size, zpool_free = zfs_get_free(args.pool_name)
perf_data = {
'free': {
'value': zpool_size, 'warn': int(zpool_size * args.warning_free), 'crit': int(zpool_size * args.critical_free), 'min': 0, 'unit': 'GB'
},
'size': {
'value': zpool_free, 'warn': int(zpool_size * args.warning_free), 'crit': int(zpool_size * args.critical_free), 'min': 0, 'unit': 'GB'
},
'fragmentation': {
'value': int(float(float_to_percent(pool_status['fragmentation']).strip('%'))), 'warn': float_to_percent(args.warning_frag), 'crit': float_to_percent(args.critical_frag), 'min': 0, 'unit': '%'
}
}
perf_data_str = dict_to_perfdata(perf_data)
print(list_to_markdown_table(table_data, align='center', seperator='!', borders=False), '|', perf_data_str)
sys.exit(exit_code) sys.exit(exit_code)
elif args.check_type in ['cache', 'log']: elif args.check_type in ['cache', 'log']:

9
checker/zfs.py Normal file
View File

@ -0,0 +1,9 @@
import subprocess
def zfs_get_free(zpool: str):
size = int(subprocess.check_output(f"zpool get -p -H size | grep {zpool} | awk '{{ print $3}}'", shell=True).decode().strip('\n'))
size_gb = int(size / 1e+9)
free = int(subprocess.check_output(f"zpool get -p -H free | grep {zpool} | awk '{{ print $3}}'", shell=True).decode().strip('\n'))
free_gb = int(free / 1e+9)
return size_gb, free_gb