forked from mtusi2026/mtusi2026lab2
Completed for a grade of five
This commit is contained in:
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reduces a k6 CSV of single requests to per-second numbers of the measure phase:
|
||||
second, requests, non-200 responses, p50/p99/max latency in ms."""
|
||||
import csv
|
||||
import math
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def percentile(values, q):
|
||||
values = sorted(values)
|
||||
return values[min(len(values) - 1, int(q * len(values)))]
|
||||
|
||||
|
||||
def main():
|
||||
path, measure_start, duration = sys.argv[1], float(sys.argv[2]), int(sys.argv[3])
|
||||
durations = defaultdict(list)
|
||||
failures = defaultdict(int)
|
||||
statuses = {}
|
||||
with open(path) as f:
|
||||
for row in csv.DictReader(f):
|
||||
if row["metric_name"] == "http_req_duration":
|
||||
second = math.floor(float(row["timestamp"]) / 1000 - measure_start)
|
||||
if 0 <= second < duration:
|
||||
durations[second].append(float(row["metric_value"]))
|
||||
if row.get("status") != "200":
|
||||
failures[second] += 1
|
||||
print("second,requests,non_200,p50_ms,p99_ms,max_ms")
|
||||
for second in range(duration):
|
||||
values = durations.get(second, [])
|
||||
if not values:
|
||||
print(f"{second},0,0,,,")
|
||||
continue
|
||||
print(f"{second},{len(values)},{failures[second]},{percentile(values, 0.5):.2f},"
|
||||
f"{percentile(values, 0.99):.2f},{max(values):.2f}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user