okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cfb4a3349
main
1"""Sample system RAM, swap and the AMD GPU's memory, load, power and temperature once per second (sysfs). 2The RTX 5090 report's monitor.py calls nvidia-smi; this reads the same quantities from amdgpu's sysfs files.""" 3import glob 4import json 5import sys 6import time 7from pathlib import Path 8 9CARD = Path (sys .argv [2 ]if len (sys .argv )> 2 else '/sys/class/drm/card1/device' ) 10HWMON = Path (glob .glob (str (CARD / 'hwmon' / 'hwmon*' ))[0 ]) 11 12 13def number (path ): 14try : 15return int (Path (path ).read_text ().strip ()) 16except (OSError ,ValueError ): 17return None 18 19 20with Path (sys .argv [1 ]if len (sys .argv )> 1 else 'telemetry.jsonl' ).open ('a' )as output : 21while True : 22memory = {} 23for line in Path ('/proc/meminfo' ).read_text ().splitlines (): 24key ,value = line .split (':' ,1 ) 25if key in ('MemTotal' ,'MemAvailable' ,'SwapTotal' ,'SwapFree' ): 26memory [key + '_KiB' ]= int (value .strip ().split ()[0 ]) 27gpu = {'vram_used_bytes' :number (CARD / 'mem_info_vram_used' ), 28'vram_total_bytes' :number (CARD / 'mem_info_vram_total' ), 29'gpu_busy_percent' :number (CARD / 'gpu_busy_percent' ), 30'power_average_uW' :number (HWMON / 'power1_average' ), 31'temperature_mC' :number (HWMON / 'temp1_input' )} 32output .write (json .dumps ({'epoch_s' :time .time (),'memory' :memory ,'gpu' :gpu })+ '\n' ) 33output .flush () 34time .sleep (1 )