def main(): """Execute Main program.""" usage = "usage: %prog [options] report1.json report2.json ..." parser = OptionParser(description=__doc__, usage=usage) parser.add_option( "-o", "--output-file", dest="outfile", default="-", help=( "If '-', then the combined report file is written to stdout." " Any other value is treated as the output file name. By default," " output is written to stdout.")) parser.add_option( "-x", "--no-report-exit", dest="report_exit", default=True, action="store_false", help="Do not exit with a non-zero code if any test in the report fails." ) (options, args) = parser.parse_args() if not args: sys.exit("No report files were specified") report_files = args report_files_count = len(report_files) test_reports = [] for report_file in report_files: try: report_file_json = read_json_file(report_file) test_reports.append(report.TestReport.from_dict(report_file_json)) except IOError as err: # errno.ENOENT is the error code for "No such file or directory". if err.errno == errno.ENOENT: report_files_count -= 1 continue raise combined_test_report = report.TestReport.combine(*test_reports) combined_report = combined_test_report.as_dict() if options.outfile == "-": outfile_exists = False # Nothing will be overridden when writing to stdout. else: outfile_exists = os.path.exists(options.outfile) check_error(report_files_count, outfile_exists) if not outfile_exists: with utils.open_or_use_stdout(options.outfile) as fh: json.dump(combined_report, fh) if options.report_exit: sys.exit(report_exit(combined_test_report)) else: sys.exit(0)
def main(): usage = "usage: %prog [options] report1.json report2.json ..." parser = OptionParser(description=__doc__, usage=usage) parser.add_option("-o", "--output-file", dest="outfile", default="-", help="If '-', then the combined report file is written to stdout." " Any other value is treated as the output file name. By default," " output is written to stdout.") parser.add_option("-x", "--no-report-exit", dest="report_exit", default=True, action="store_false", help="Do not exit with a non-zero code if any test in the report fails.") (options, args) = parser.parse_args() if not args: sys.exit("No report files were specified") report_files = args report_files_count = len(report_files) test_reports = [] for report_file in report_files: try: report_file_json = read_json_file(report_file) test_reports.append(report.TestReport.from_dict(report_file_json)) except IOError as e: # errno.ENOENT is the error code for "No such file or directory". if e.errno == errno.ENOENT: report_files_count -= 1 continue raise combined_test_report = report.TestReport.combine(*test_reports) combined_report = combined_test_report.as_dict() if options.outfile == "-": outfile_exists = False # Nothing will be overridden when writing to stdout. else: outfile_exists = os.path.exists(options.outfile) check_error(report_files_count, outfile_exists) if not outfile_exists: with utils.open_or_use_stdout(options.outfile) as fh: json.dump(combined_report, fh) if options.report_exit: sys.exit(report_exit(combined_test_report)) else: sys.exit(0)
def main(): usage = "usage: %prog [options]" parser = optparse.OptionParser(description=__doc__, usage=usage) parser.add_option( "-i", "--interval", dest="interval", default=5, type="int", help="Collect system resource information every <interval> seconds. " "Default is every 5 seconds.") parser.add_option( "-o", "--output-file", dest="outfile", default="-", help="If '-', then the file is written to stdout." " Any other value is treated as the output file name. By default," " output is written to stdout.") (options, _) = parser.parse_args() with utils.open_or_use_stdout(options.outfile) as fp: while True: try: # 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. 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)
def main(): usage = "usage: %prog [options]" parser = optparse.OptionParser(description=__doc__, usage=usage) parser.add_option("-i", "--interval", dest="interval", default=5, type="int", help="Collect system resource information every <interval> seconds. " "Default is every 5 seconds.") parser.add_option("-o", "--output-file", dest="outfile", default="-", help="If '-', then the file is written to stdout." " Any other value is treated as the output file name. By default," " output is written to stdout.") (options, _) = parser.parse_args() 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. 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)