From 22984260e622dcbc420ccc99b8e1a12fc7d789d9 Mon Sep 17 00:00:00 2001 From: Mark Grimes Date: Sat, 30 Sep 2023 14:40:43 -0700 Subject: [PATCH] Add text file, nfs-client-counts.txt, collecting the number of NFS clients by type --- ixdiagnose/plugins/nfs.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ixdiagnose/plugins/nfs.py b/ixdiagnose/plugins/nfs.py index 2f47a4a..3edf3a0 100644 --- a/ixdiagnose/plugins/nfs.py +++ b/ixdiagnose/plugins/nfs.py @@ -1,11 +1,27 @@ from ixdiagnose.utils.command import Command -from ixdiagnose.utils.middleware import MiddlewareCommand +from ixdiagnose.utils.middleware import MiddlewareClient, MiddlewareCommand +from typing import Any from .base import Plugin -from .metrics import CommandMetric, FileMetric, MiddlewareClientMetric +from .metrics import CommandMetric, FileMetric, MiddlewareClientMetric, PythonMetric from .prerequisites import ServiceRunningPrerequisite +def nfs_client_count_by_type(client: MiddlewareClient, context: Any) -> str: + num_nfs3 = client.call('nfs.get_nfs3_clients') + nfs4_clnt_info = client.call('nfs.get_nfs4_clients') + nfs4_ver_info = [x["info"]["minor version"] for x in nfs4_clnt_info] + + title = 'Number of NFS clients' + output = f'{"=" * (len(title) + 5)}\n {title}\n{"=" * (len(title) + 5)}\n\n' + output += f'NFSv3: {len(num_nfs3)}\n' + output += f'NFSv4.2: {nfs4_ver_info.count(2)}\n' + output += f'NFSv4.1: {nfs4_ver_info.count(1)}\n' + output += f'NFSv4.0: {nfs4_ver_info.count(0)}\n' + + return output + + class NFS(Plugin): name = 'nfs' metrics = [ @@ -39,4 +55,5 @@ class NFS(Plugin): MiddlewareCommand('nfs.config'), MiddlewareCommand('sharing.nfs.query'), ]), + PythonMetric('nfs-client-counts', nfs_client_count_by_type, serializable=False), ]