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), ]