summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNitin Goyal <nigoyal@redhat.com>2020-02-14 10:33:36 +0530
committerVaibhav Mahajan <vamahaja@redhat.com>2020-03-18 06:03:40 +0000
commitf5584bc78c9fb3577e407c2f73a9b4c7f42a2ced (patch)
tree6a4b0468379edd5dc8b941dc57f0d9a104830aff
parentc42a4c07e0aec2bd4036e853d1f3e39c15856c26 (diff)
[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 <nigoyal@redhat.com>
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/process_ops.py33
1 files changed, 33 insertions, 0 deletions
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')
+ ]