okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ef8071303
main
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 (): 15parser = argparse .ArgumentParser (description = __doc__ ) 16parser .add_argument ("--url" ,default = "http://127.0.0.1:8080" ) 17parser .add_argument ("--out" ,default = "/data/bench/telemetry.jsonl" ) 18parser .add_argument ("--seconds" ,type = int ,default = 1200 ) 19args = parser .parse_args () 20started = time .time () 21with open (args .out ,"w" ,encoding = "utf-8" )as sink : 22while time .time ()- started < args .seconds : 23try : 24with urllib .request .urlopen (args .url + "/metrics" ,timeout = 10 )as response : 25metrics = json .load (response ) 26engine ,hardware = metrics ["engine" ],metrics ["hardware" ] 27live = metrics .get ("live" , {}) 28sink .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" ) 45sink .flush () 46except Exception as error :# a sample may race a restart; keep going 47sink .write (json .dumps ({"t" :round (time .time ()- started ,3 ),"error" :str (error )})+ "\n" ) 48sink .flush () 49time .sleep (1 ) 50 51 52if __name__ == "__main__" : 53main ()