diff --git a/orchestrator.py b/orchestrator.py index b863785..b93a0f3 100644 --- a/orchestrator.py +++ b/orchestrator.py @@ -6,6 +6,9 @@ import json import time import re import pprint +import subprocess + +from jinja2 import Template total_start = time.time() @@ -100,11 +103,6 @@ try: container.reload() # Refresh container status - print(f"""Performance: - Max CPU: {max_cpu_percent:.2f}% - Max Memory: {max_memory_mb:.2f}MB - Total Transfer: {(total_rx_bytes + total_tx_bytes) / 1024} KBs""") - container.wait() print("Container logs:") @@ -119,6 +117,41 @@ try: print(f"\t{line}") container.remove() + + metrics = [ + {"name": "Max CPU", "value": f"{max_cpu_percent:.2f}", "unit": "%"}, + {"name": "Max Memory", "value": f"{max_memory_mb:.2f}", "unit": "MB"}, + {"name": "Total Transfer", "value": f"{(total_rx_bytes + total_tx_bytes) / 1024:.0f}", "unit": "KB"}, + {"name": "Cold Start Time", "value": f"{(coldstart_stop_time - container_start_time):.3f}", "unit": "seconds"}, + {"name": "Time to Response", "value": f"{(scrape_stop_time - scrape_start_time):.3f}", "unit": "seconds"}, + {"name": "Total Runtime", "value": f"{(time.time() - total_start):.3f}", "unit": "seconds"} + ] + + with open('output/output.txt', 'r', encoding='utf-8') as f: + text_content = f.read() + + with open('report.html', 'r') as f: + template = Template(f.read()) + + rendered_html = template.render(metrics=metrics, text_content=text_content) + + with open('output/report.html', 'w') as f: + f.write(rendered_html) + + # Try running `open` to launch the html file automatically, fail silently + try: + subprocess.run(['open', 'output/report.html']) + print("Report opened in browser") + except (subprocess.CalledProcessError, FileNotFoundError): + print("what happened") + pass + + + print(f"""Performance: + Max CPU: {max_cpu_percent:.2f}% + Max Memory: {max_memory_mb:.2f}MB + Total Transfer: {(total_rx_bytes + total_tx_bytes) / 1024} KBs""") + print(f"Cold Start Time: {(coldstart_stop_time - container_start_time):.3f} seconds") print(f"Time to Response: {(scrape_stop_time - scrape_start_time):.3f} seconds") print(f"Completed everything in: {(time.time() - total_start):.3f} seconds") diff --git a/report.html b/report.html new file mode 100644 index 0000000..a28f8d4 --- /dev/null +++ b/report.html @@ -0,0 +1,56 @@ + + +
+ + +Metric | +Value | +Unit | +
---|---|---|
{{ metric.name }} | +{{ metric.value }} | +{{ metric.unit }} | +