ЛР 6 — БПИ2302 — Нурлыгаянова — на 3

This commit is contained in:
Nurlygayanova Ekaterina
2026-11-13 11:32:45 +03:00
parent 470d9d6f1e
commit 69a190be0e
164 changed files with 25947 additions and 29 deletions
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""30s closed-loop workload plus sampled Docker CPU/RAM (not peak measurement)."""
import json
import platform
import subprocess
import sys
import time
from pathlib import Path
root = Path(__file__).resolve().parents[1]
with (root/'evidence'/'load.txt').open('w') as output:
process = subprocess.Popen([sys.executable,'tests/load.py','--base-url','http://localhost:18086',
'--duration','30','--concurrency','4','--output','evidence/load.json'],cwd=root,stdout=output,stderr=subprocess.STDOUT)
samples = []
while process.poll() is None:
raw = subprocess.check_output(['docker','stats','--no-stream','--format','{{json .}}'],text=True)
samples.append({'unix':time.time(),'containers':[json.loads(line) for line in raw.splitlines() if 'mtusi-lab6-' in line]})
time.sleep(3)
if process.returncode:
raise SystemExit(process.returncode)
info = json.loads(subprocess.check_output(['docker','info','--format','{{json .}}'],text=True))
result = {'host':platform.platform(),'docker':{'os':info['OperatingSystem'],'cpus':info['NCPU'],'memory_bytes':info['MemTotal']},
'note':'CPU/RAM snapshots during workload, not peaks; Docker Desktop shared with other local services.', 'samples':samples}
(root/'evidence'/'resources.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n')
print('PASS: evidence/load.json and evidence/resources.json')