From f5584bc78c9fb3577e407c2f73a9b4c7f42a2ced Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 14 Feb 2020 10:33:36 +0530 Subject: [Lib] Add lib to get the memory of running process Add lib 'get_process_memory_on_gluster_pod_or_node' to get the memory of running proces inside gluster pod or node. Change-Id: Ide2b09569407e8cf09c72af638d741d5926431c4 Signed-off-by: Nitin Goyal --- .../openshiftstoragelibs/process_ops.py | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 openshift-storage-libs/openshiftstoragelibs/process_ops.py (limited to 'openshift-storage-libs/openshiftstoragelibs') diff --git a/openshift-storage-libs/openshiftstoragelibs/process_ops.py b/openshift-storage-libs/openshiftstoragelibs/process_ops.py new file mode 100644 index 00000000..16bc505c --- /dev/null +++ b/openshift-storage-libs/openshiftstoragelibs/process_ops.py @@ -0,0 +1,33 @@ +"""Module for doing process related tasks such as ps info.""" + +from openshiftstoragelibs.openshift_ops import ( + cmd_run_on_gluster_pod_or_node, +) + + +def get_process_info_on_gluster_pod_or_node( + master, g_node, process, fields): + """Get the info of the running process in the gluster node or pod. + + Args: + master (str): master node of ocp cluster. + g_node (str): ip or hostname of gluster node. + process (str): name of the process. + e.g. 'glusterfsd' + fields (list): field names of the process. + e.g. ['pid', 'rss', 'vsz', '%cpu'] + + Returns: + list: [ + {field1: val, field2: val}, + {field1: val, field2: val} + ] + """ + + cmd = "ps -C {} -o {} --no-headers".format(process, ','.join(fields)) + + out = cmd_run_on_gluster_pod_or_node(master, cmd, g_node) + + return [ + dict(list(zip(fields, prc.strip().split()))) for prc in out.split('\n') + ] -- cgit