feat(scripts): rolling update and failover under k6 load
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Собирает метрики из k6 summary-export в плоский CSV.
|
||||
|
||||
Использование:
|
||||
python3 scripts/collect-metrics.py evidence/*-k6.json > evidence/summary.csv
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
FIELDS = [
|
||||
("http_reqs", "rate"),
|
||||
("http_req_failed", "rate"),
|
||||
("write_errors", "rate"),
|
||||
("write_total", "count"),
|
||||
("write_latency_ms", "avg"),
|
||||
("write_latency_ms", "p(90)"),
|
||||
("write_latency_ms", "p(95)"),
|
||||
("write_latency_ms", "max"),
|
||||
("http_req_duration", "p(95)"),
|
||||
("http_req_duration", "p(99)"),
|
||||
]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 2:
|
||||
print("usage: collect-metrics.py <k6-summary.json> ...", file=sys.stderr)
|
||||
return 2
|
||||
print("run,metric,value")
|
||||
for path in sys.argv[1:]:
|
||||
name = Path(path).stem
|
||||
try:
|
||||
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
print(f"# skip {path}: {exc}", file=sys.stderr)
|
||||
continue
|
||||
metrics = data.get("metrics", {})
|
||||
for metric, key in FIELDS:
|
||||
entry = metrics.get(metric)
|
||||
if not entry:
|
||||
continue
|
||||
values = entry.get("values", entry)
|
||||
value = values.get(key)
|
||||
if value is None:
|
||||
continue
|
||||
print(f"{name},{metric}.{key},{value}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user