okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-141-fixb: Python, docs and bench fixes and portsef8071303

main
2.3 KiB53 linesraw
1#!/usr/bin/env python3
2"""Sample Strata's own /metrics once per second into JSONL.
3
4Runs inside the container next to the benchmark. Every sample keeps the engine's
5own view of memory (bytes), which is the only view available for VRAM inside the
6container: nvidia-smi reports the whole GPU's allocation, not the container's.
7"""
8import argparse
9import json
10import time
11import urllib.request
12
13
14def main():
15    parser = argparse.ArgumentParser(description=__doc__)
16    parser.add_argument("--url", default="http://127.0.0.1:8080")
17    parser.add_argument("--out", default="/data/bench/telemetry.jsonl")
18    parser.add_argument("--seconds", type=int, default=1200)
19    args = parser.parse_args()
20    started = time.time()
21    with open(args.out, "w", encoding="utf-8") as sink:
22        while time.time() - started < args.seconds:
23            try:
24                with urllib.request.urlopen(args.url + "/metrics", timeout=10) as response:
25                    metrics = json.load(response)
26                engine, hardware = metrics["engine"], metrics["hardware"]
27                live = metrics.get("live", {})
28                sink.write(json.dumps({
29                    "t": round(time.time() - started, 3),
30                    "gpu_mem_used": hardware["gpu_mem_used"],
31                    "gpu_mem_total": hardware["gpu_mem_total"],
32                    "gpu_util": hardware["gpu_util"],
33                    "gpu_temp_c": hardware["gpu_temp"],
34                    "gpu_power_w": hardware["gpu_power"],
35                    "gpu_pcie_gen": hardware["gpu_pcie_gen"],
36                    "gpu_pcie_width": hardware["gpu_pcie_width"],
37                    "ram_used": hardware["ram_used"],
38                    "ram_total": hardware["ram_total"],
39                    "disk_read_mb": hardware.get("disk_read_mb"),
40                    "vram_free_mib": engine["vram_free_mib"],
41                    "expert_cache_mib": engine["expert_cache_mib"],
42                    "state": live.get("state"),
43                    "tok_s": live.get("tok_s"),
44                }) + "\n")
45                sink.flush()
46            except Exception as error:                       # a sample may race a restart; keep going
47                sink.write(json.dumps({"t": round(time.time() - started, 3), "error": str(error)}) + "\n")
48                sink.flush()
49            time.sleep(1)
50
51
52if __name__ == "__main__":
53    main()