okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cc52598ab
main
1"""Sample system RAM, swap and both AMD GPUs' memory, busy and power once per second (sysfs; the AMD form of 2bench/results/2026-09-30-community-rtx-5090/monitor.py).""" 3import glob ,json ,sys ,time 4from pathlib import Path 5out = Path (sys .argv [1 ]if len (sys .argv )> 1 else 'telemetry.jsonl' ) 6cards = sorted (glob .glob ('/sys/class/drm/card[0-9]/device' )) 7def rd (p ): 8try :return int (Path (p ).read_text ().split ()[0 ]) 9except Exception :return None 10with out .open ('a' )as f : 11while True : 12memory = {} 13for line in Path ('/proc/meminfo' ).read_text ().splitlines (): 14key ,value = line .split (':' ,1 ) 15if key in ('MemTotal' ,'MemAvailable' ,'SwapTotal' ,'SwapFree' ): 16memory [key + '_KiB' ]= int (value .strip ().split ()[0 ]) 17gpus = [] 18for d in cards : 19hw = glob .glob (d + '/hwmon/hwmon*/' ) 20hw = hw [0 ]if hw else '' 21gpus .append ({'pci' :Path (d ).resolve ().name ,'vram_used_MiB' : (rd (d + '/mem_info_vram_used' )or 0 )// 1048576 , 22'gtt_used_MiB' : (rd (d + '/mem_info_gtt_used' )or 0 )// 1048576 ,'busy_percent' :rd (d + '/gpu_busy_percent' ), 23'power_W' : (rd (hw + 'power1_average' )or rd (hw + 'power1_input' )or 0 )/ 1e6 if hw else None , 24'temp_C' : (rd (hw + 'temp1_input' )or 0 )/ 1000 if hw else None }) 25f .write (json .dumps ({'epoch_s' :time .time (),'memory' :memory ,'gpus' :gpus })+ '\n' );f .flush () 26time .sleep (1 )