Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wazuh-metrics for reconnecting daemons using multiprocessing #2401

Closed
vicferpoy opened this issue Dec 24, 2021 · 0 comments · Fixed by #2416
Closed

Fix wazuh-metrics for reconnecting daemons using multiprocessing #2401

vicferpoy opened this issue Dec 24, 2021 · 0 comments · Fixed by #2416
Assignees
Labels
tool/wazuh-metrics Development that involves modifying the wazuh-metrics script/tool

Comments

@vicferpoy
Copy link
Contributor

In #2258, we adapted the wazuh-metrics CLI to allow monitoring child processes as multiprocessing was implemented for the Wazuh API and cluster.

However, with the current design it was not possible to keep monitoring said processes if they restarted:

except psutil.NoSuchProcess:
logger.warning(f'Lost PID for {self.process_name}. Trying to obtain a new one. '
'If the process has child processes, this test will not be valid')
try:
# Try to get another PID for the current process name. This could be wrong if there is more than
# one process with the same name (child processes)
self.pid = Monitor.get_process_pids(self.process_name, check_children=False)[0]
self.set_process()
except ValueError:
logger.warning(f'Could not obtain a new PID for {self.process_name}. Trying again in {self.time_step}s')
finally:
info.update({key: round(value, 2) for key, value in info.items() if isinstance(value, (int, float))})
logger.debug(f'Recollected data for process {self.pid}')
return info

This is needed now as it is not compatible with our API performance tests due to their restart endpoints:

  • api.log
2021/12/23 18:29:01 INFO: unknown_user 172.31.39.92 "GET /security/users/me/policies" with parameters {} and body {} done in 0.013s: 400
2021/12/23 18:29:24 INFO: Listening on 0.0.0.0:55000..
2021/12/23 18:29:31 INFO: wazuh 172.31.32.132 "GET /" with parameters {} and body {} done in 4.788s: 200
2021/12/23 18:29:32 INFO: wazuh-wui 172.31.39.92 "GET /manager/stats/analysisd" with parameters {"pretty": "True"} and body {} done in 0.135s: 200
2021/12/23 18:29:32 INFO: wazuh 172.31.32.132 "PUT /cluster/restart" with parameters {} and body {} done in 0.165s: 200
2021/12/23 18:29:35 INFO: unknown_user 172.31.39.92 "GET /cluster/status" with parameters {} and body {} done in 0.005s: 400
2021/12/23 18:29:58 INFO: Listening on 0.0.0.0:55000..
  • One of the API processes CPU usage
wazuh-apid_child_1,4.3.0,2021/12/23 18:28:53,20389,40.1,342528.0,90220.0,63012.0,70317.0,0.0,28,4455,208,1621.0,152.0,12.8,0.0
wazuh-apid_child_1,4.3.0,2021/12/23 18:28:58,20389,21.5,345484.0,93052.0,65876.0,73163.0,0.0,28,6061,308,1625.0,352.0,0.8,40.0
wazuh-apid_child_1,4.3.0,2021/12/23 18:29:03,20389,-721.1,242944.0,33060.0,28516.0,28881.0,0.0,16,833,15,0.0,0.0,-325.0,-70.4
wazuh-apid_child_1,4.3.0,2021/12/23 18:29:08,20389,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
wazuh-apid_child_1,4.3.0,2021/12/23 18:29:13,20389,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0

image

A rework of both the CLI and the Monitor class is needed to solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool/wazuh-metrics Development that involves modifying the wazuh-metrics script/tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant