Change method of getting PIDs of running processes

Change-Id: I669cd6f4fd52d04de9ed6087719e8910d570505e
This commit is contained in:
Artem 2016-10-05 17:38:22 +03:00
parent 3830c0fdc3
commit e45613ce8c
2 changed files with 15 additions and 10 deletions

View File

@ -66,17 +66,18 @@ def simulate_network_interrupt_on_node(remote, interval=30):
remote.execute(cmd) remote.execute(cmd)
def get_pids_of_process(remote, name): def get_pids_of_process(remote, cmd_pattern):
"""Get PIDs of process by its name. """Get PIDS of process by its pattern.
:param remote: SSH connection to the node. :param remote: SSH connection to the node.
:type remote: SSHClient :type remote: SSHClient
:param name: process name. :param cmd_pattern: command.
:type name: str :type cmd_pattern: str
:returns: list of PIDs. :returns: list of PIDS.
:rtype: list :rtype: list
""" """
cmd = "pidof {}".format(name)
cmd = "pgrep -f '{}'".format(cmd_pattern)
result = remote.execute(cmd) result = remote.execute(cmd)
if result['exit_code'] != 0: if result['exit_code'] != 0:
return [] return []

View File

@ -37,18 +37,22 @@ class LMACollectorPluginApi(base_test.PluginApi):
:returns: list of process IDs indexed by node and process :returns: list of process IDs indexed by node and process
:rtype: dict :rtype: dict
""" """
services = ["metric_collector", "log_collector"]
service_version_9 = ["lma_collector"]
pids = {} pids = {}
processes_count = { processes_count = {
"collectd": 1, "collectd ": 1,
"collectdmon": 1 "collectdmon ": 1
} }
if self.settings.version.startswith("0.9"): if self.settings.version.startswith("0.9"):
processes_count["hekad"] = 1 processes_count[
"hekad -config[= ]/etc/{}".format(service_version_9)] = 1
else: else:
# Starting with 0.10, there are one collector for logs and one for # Starting with 0.10, there are one collector for logs and one for
# metrics # metrics
processes_count["hekad"] = 2 for service in services:
processes_count["hekad -config[= ]/etc/{}".format(service)] = 1
online_nodes = [node for node in self.helpers.get_all_ready_nodes() online_nodes = [node for node in self.helpers.get_all_ready_nodes()
if node["online"]] if node["online"]]
for node in online_nodes: for node in online_nodes: