diff options
author | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-19 15:19:16 -0400 |
---|---|---|
committer | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-22 17:39:40 -0400 |
commit | 00b88359c7c1440c519c0d06afbcd3c181fa0bbb (patch) | |
tree | 1fa6fa4b58bc25586d6477a40a454e9ef37410a2 | |
parent | fc3a452a6ecb35914b9df98b19309b03de644fd6 (diff) | |
download | mongo-00b88359c7c1440c519c0d06afbcd3c181fa0bbb.tar.gz |
SERVER-37467 Have collect_resource_info.py recover from transient errors.
(cherry picked from commit f86b57ac39110510321469c70c7a76e9232d5530)
-rwxr-xr-x | buildscripts/collect_resource_info.py | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/buildscripts/collect_resource_info.py b/buildscripts/collect_resource_info.py index 56bbb073fca..8684aac0de9 100755 --- a/buildscripts/collect_resource_info.py +++ b/buildscripts/collect_resource_info.py @@ -44,54 +44,57 @@ def main(): with utils.open_or_use_stdout(options.outfile) as fp: while True: - # Requires the Evergreen agent to be running on port 2285. - response = requests.get("http://localhost:2285/status") - if response.status_code != requests.codes.ok: - print("Received a {} HTTP response: {}".format(response.status_code, response.text), - file=sys.stderr) - time.sleep(options.interval) - continue - - timestamp = datetime.now() try: - res_json = response.json() - except ValueError: - print("Invalid JSON object returned with response: {}".format(response.text), - file=sys.stderr) - time.sleep(options.interval) - continue - - sys_res_dict = {} - sys_res_dict["timestamp"] = timestamp - sys_info = res_json["sys_info"] - sys_res_dict["num_cpus"] = sys_info["num_cpus"] - sys_res_dict["mem_total"] = sys_info["vmstat"]["total"] - sys_res_dict["mem_avail"] = sys_info["vmstat"]["available"] - ps_info = res_json["ps_info"] - for process in ps_info: - try: - sys_res_dict["pid"] = process["pid"] - sys_res_dict["ppid"] = process["parentPid"] - sys_res_dict["num_threads"] = process["numThreads"] - sys_res_dict["command"] = process.get("command", "") - sys_res_dict["cpu_user"] = process["cpu"]["user"] - sys_res_dict["cpu_sys"] = process["cpu"]["system"] - sys_res_dict["io_wait"] = process["cpu"]["iowait"] - sys_res_dict["io_write"] = process["io"]["writeBytes"] - sys_res_dict["io_read"] = process["io"]["readBytes"] - sys_res_dict["mem_used"] = process["mem"]["rss"] - except KeyError: - # KeyError may occur as a result of file missing from /proc, likely due to - # process exiting. + # Requires the Evergreen agent to be running on port 2285. + response = requests.get("http://localhost:2285/status") + if response.status_code != requests.codes.ok: + print("Received a {} HTTP response: {}".format(response.status_code, + response.text), file=sys.stderr) + time.sleep(options.interval) continue - print(dumps(sys_res_dict, sort_keys=True), file=fp) + timestamp = datetime.now() + try: + res_json = response.json() + except ValueError: + print("Invalid JSON object returned with response: {}".format(response.text), + file=sys.stderr) + time.sleep(options.interval) + continue - if fp.fileno() != sys.stdout.fileno(): - # Flush internal buffers associated with file to disk. - fp.flush() - os.fsync(fp.fileno()) - time.sleep(options.interval) + sys_res_dict = {} + sys_res_dict["timestamp"] = timestamp + sys_info = res_json["sys_info"] + sys_res_dict["num_cpus"] = sys_info["num_cpus"] + sys_res_dict["mem_total"] = sys_info["vmstat"]["total"] + sys_res_dict["mem_avail"] = sys_info["vmstat"]["available"] + ps_info = res_json["ps_info"] + for process in ps_info: + try: + sys_res_dict["pid"] = process["pid"] + sys_res_dict["ppid"] = process["parentPid"] + sys_res_dict["num_threads"] = process["numThreads"] + sys_res_dict["command"] = process.get("command", "") + sys_res_dict["cpu_user"] = process["cpu"]["user"] + sys_res_dict["cpu_sys"] = process["cpu"]["system"] + sys_res_dict["io_wait"] = process["cpu"]["iowait"] + sys_res_dict["io_write"] = process["io"]["writeBytes"] + sys_res_dict["io_read"] = process["io"]["readBytes"] + sys_res_dict["mem_used"] = process["mem"]["rss"] + except KeyError: + # KeyError may occur as a result of file missing from /proc, likely due to + # process exiting. + continue + + print(dumps(sys_res_dict, sort_keys=True), file=fp) + + if fp.fileno() != sys.stdout.fileno(): + # Flush internal buffers associated with file to disk. + fp.flush() + os.fsync(fp.fileno()) + time.sleep(options.interval) + except requests.ConnectionError as error: + print(error, file=sys.stderr) if __name__ == "__main__": |