okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
66331f9bc
main
1import { localeTag } from '../lib/i18n' ; 2import { tr } from '../lib/i18n' ; 3import { scopedMonitor , instanceLabel , deviceLabel } from '../lib/runtime-models' ; 4/** The original Strata dashboard, adapted to the current shell and device inventory. */ 5import { useEffect , useRef , useState , type ReactNode } from 'react' ; 6import { flushSync } from 'react-dom' ; 7import { SnapshotDialog } from '../components/SnapshotDialog' ; 8import { requestSummary } from '../lib/monitor-summary' ; 9import { monitorPng } from '../lib/snapshot' ; 10import { Gauge , ReferenceSpark } from '../components/charts' ; 11import { Brand } from '../components/Brand' ; 12import { Bar , Btn , Icon , IconBtn , Select , type IconName } from '../components/ui' ; 13import { Screen } from '../components/layout' ; 14import { contextLabel , duration , tokens , tps } from '../lib/format' ; 15import { defaultGpuSet , gpuCapacity , gpuId , gpuMetric , gpuReported , hasReading , shortGpuName } from '../lib/monitor-hardware' ; 16import { useStore } from '../lib/store' ; 17import { api } from '../lib/client' ; 18import { useMoney } from '../lib/money' ; 19import { useKept } from '../lib/kept-state' ; 20import type { Hardware , MonitorState , ServeRequest } from '../lib/types' ; 21import { useNative , nativeRouting , type NativeState } from '../lib/native' ; 22import { nativeMonitorData , withHostSensors } from '../lib/native-monitor' ; 23const number = ( value :number | null | undefined , digits = 0 ) => hasReading ( value ) ?value . toLocaleString ( localeTag (), { maximumFractionDigits :digits , minimumFractionDigits :digits }) :'—' ; 24const percent = ( used :number | null | undefined , total :number | null | undefined ) => hasReading ( used ) && hasReading ( total ) && total > 0 ?Math . max ( 0 , Math . min ( 100 , used / total * 100 )) :null ; 25const sourceLabel = ( source :string | undefined ) => source === 'demo' ?'Illustrative' :source === 'sensor' || source === 'engine' || source === 'reported' ?'Measured' :source === 'estimated' ?'Estimated' :'Unavailable' ; 26function ReadingBar ({ label, value, tone= 'accent' } :{ 27label :string ; 28value :number | null ; 29tone ?:'accent' | 'info' | 'warn' | 'danger' ; 30}) { 31return hasReading ( value ) ?< Bar label = { tr ( label )} value = { value } tone = { tone }/> :< div className = "st-progress" role = "img" aria-label = { tr ( "{0}: unavailable" , [ label ])}/>; 32} 33function MonitorMetric ({ label, icon, value, unit, sub, chart, source, secondary} :{ 34label :string ; 35icon :IconName ; 36value :ReactNode ; 37unit ?:string ; 38sub :ReactNode ; 39chart :ReactNode ; 40source :string ; 41secondary ?:ReactNode ; 42}) { 43return < section className = "st-card monitor-metric" aria-label = { tr ( label )}> 44< div className = "st-metric__label" >< Icon name = { icon } size = { 18 }/>{ tr ( label )}< span className = "monitor-metric__source xs" >{ tr ( source )}</ span ></ div > 45< div className = { secondary ?'monitor-speed-values' :'monitor-metric__reading' }>< div >< div className = "st-metric__value" >{ tr ( value )}{ tr ( unit ?< span className = "st-metric__unit" >{ tr ( unit )}</ span > :null )}</ div >< div className = "monitor-metric__sub xs muted" >{ tr ( sub )}</ div ></ div >{ tr ( secondary )}</ div > 46{ tr ( chart )} 47</ section >; 48} 49function requestStatus ( request :ServeRequest ) { 50if ( request . state === 'error' ) 51return 'Error' ; 52if ( request . state === 'queued' ) 53return 'Queued' ; 54if ( request . state === 'generating' ) 55return 'Generating' ; 56if ( request . cancelRequested || [ 'cancel' , 'disconnect' ]. includes ( request . finishReason ?? '' )) 57return 'Stopped' ; 58return [ 'length' , 'max_tokens' ]. includes ( request . finishReason ?? '' ) ?'Max tokens' :'Done' ; 59} 60export function MonitorScreen () { 61const native = useNative (); 62// While this screen is open and visible the host reads the graphics card every 3 s; otherwise it asks only every 30 s (#4066). 63useEffect (() => { 64const ask = () => { if ( typeof document === 'undefined' || document . visibilityState !== 'hidden' ) 65void api . get ( '/api/monitor?drives=1' ). catch (() => undefined ); }; 66ask (); 67const timer = setInterval ( ask , 10000 ); 68return () => clearInterval ( timer ); 69}, []); 70return < LegacyMonitorScreen native = { native ?. instances . length ?native :null }/>; 71} 72function LegacyMonitorScreen ({ native} :{ 73native :NativeState | null ; 74}) { 75const storedLive = useStore ( s => s . monitor ), inventory = useStore ( s => s . hardware ); 76const electricityPrice = useStore ( s => s . electricityPrice ), money = useMoney (); 77const storedRuntime = useStore ( s => s . runtime ), serving = useStore ( s => s . serving ); 78const [ instanceSelection , setInstanceSelection ] = useState ( 'all' ); 79const routing = native ?nativeRouting ( native , inventory ) :null ; 80const runtime = routing && native ?{ ...routing , instances :routing . instances . map ( instance => { const raw = native . instances . find ( item => item . id === instance . id )?. metrics ?. live ; return { ...instance , outputTps :raw ?. tok_s ?? NaN , promptTps :raw ?. prefill_tok_s_mean ?? NaN , active :raw ?( raw . running ?? ([ 'reading' , 'generating' ]. includes ( raw . state ) ?1 :0 )) :NaN , queued :raw ?. queued ?? NaN }; }) } :storedRuntime ; 81const live = native ?withHostSensors ( nativeMonitorData ( native , inventory , instanceSelection ), storedLive ) :storedLive ; 82const multipleModels = ( runtime ?. instances . length ?? 0 ) > 1 ; 83const selectedInstance = runtime ?. instances . find ( i => i . id === instanceSelection ) ?? ( ! multipleModels ?runtime ?. instances [ 0 ] :undefined ); 84const selection = selectedInstance ?. id ?? 'all' ; 85const scoped = native ?live :scopedMonitor ( live , runtime ?? null , selection , serving ?. requests ?? []); 86const scopeLabel = selectedInstance ?instanceLabel ( selectedInstance ) :` ${ runtime ?. instances . length ?? 0 } loaded models` ; 87// null = the person has not chosen: a model with assigned cards shows those (#3211); a choice is kept while the app stays open. 88const [ gpuSelection , setGpuSelection ] = useKept < string | null >( 'monitor.gpu' , null ), [ cpuSelection , setCpuSelection ] = useState ( 'all' ), [ showAll , setShowAll ] = useState ( false ); 89const [ frozen , setFrozen ] = useState <{ 90data :MonitorState ; 91hardware :Hardware | null ; 92time :string ; 93modelLabel :string ; 94} | null >( null ); 95const snapshotRef = useRef < HTMLDivElement >( null ); 96const [ saving , setSaving ] = useState ( false ), [ saveError , setSaveError ] = useState ( '' ); 97const [ snapshotOpen , setSnapshotOpen ] = useState ( false ), [ screenshot , setScreenshot ] = useState ( '' ); 98async function saveScreenshot () { 99if ( ! live || ! snapshotRef . current || saving ) 100return ; 101setSnapshotOpen ( true ); 102setScreenshot ( '' ); 103setSaving ( true ); 104setSaveError ( '' ); 105flushSync (() => setFrozen ({ data :structuredClone ( scoped ?? live ), hardware :structuredClone ( inventory ), time :new Date (). toLocaleString ( localeTag ()), modelLabel :scopeLabel })); 106try { 107setScreenshot ( await monitorPng ( snapshotRef . current )); 108} 109catch ( error ) { 110setSaveError ( error instanceof Error ?error . message :'Screenshot could not be saved.' ); 111} 112finally { 113setFrozen ( null ); 114setSaving ( false ); 115} 116} 117const data = frozen ?. data ?? scoped , hardware = frozen ?. hardware ?? inventory ; 118if ( ! data ) 119return < Screen title = { tr ( "Monitor" )}>< p className = "muted" >{ tr ( "Waiting for engine telemetry\u2026" )}</ p ></ Screen >; 120// A display adapter that has no sensors and no memory of its own (an integrated one) cannot be measured; counting it would blank every total. 121const devices = ( hardware ?. gpus ?? []). filter ( g => g . backend !== 'vulkan' || g . vramGb > 0 ), defaultDevices = defaultGpuSet ( devices ), processors = hardware ?. processors ?. length ?hardware . processors :hardware ?[{ ...hardware . cpu , id :'cpu' , socket :'' }] :[]; 122const assignedDevices = selectedInstance ?devices . filter ( g => selectedInstance . gpuIds . includes ( gpuId ( g ))) :[]; 123const gpuChoice = gpuSelection === 'assigned' && selectedInstance ?'assigned' :devices . some ( g => gpuId ( g ) === gpuSelection ) ?gpuSelection ! :gpuSelection === 'all' || ! assignedDevices . length ?'all' :'assigned' ; 124const cpuChoice = processors . some ( p => p . id === cpuSelection ) ?cpuSelection :'all' ; 125const selectedGpus = gpuChoice === 'assigned' ?devices . filter ( g => selectedInstance ?. gpuIds . includes ( gpuId ( g ))) :gpuChoice === 'all' ?defaultDevices :devices . filter ( g => gpuId ( g ) === gpuChoice ); 126const selectedCpus = cpuChoice === 'all' ?processors :processors . filter ( p => p . id === cpuChoice ); 127const multipleGpus = selectedGpus . length > 1 , shared = selectedGpus . length > 0 && selectedGpus . every ( g => g . unified ); 128const readings = data . hardware . gpus ; 129// A card that cannot report a value (an integrated one with no temperature sensor) is left out of that value, and the card the figure is from is named. 130const report = ( key :Parameters < typeof gpuMetric >[ 2 ], mode :Parameters < typeof gpuMetric >[ 3 ] = 'sum' ) => gpuReported ( selectedGpus , readings , key , mode ); 131const gpuValue = ( key :Parameters < typeof gpuMetric >[ 2 ], mode :Parameters < typeof gpuMetric >[ 3 ] = 'sum' ) => report ( key , mode ). value ; 132const whose = ( key :Parameters < typeof gpuMetric >[ 2 ], mode :Parameters < typeof gpuMetric >[ 3 ] = 'sum' ) => { const r = report ( key , mode ); return r . partial ?r . devices . map ( d => shortGpuName ( d . name )). join ( ' + ' ) :null ; }; 133const gpuSource = ( key :Parameters < typeof gpuMetric >[ 2 ], mode :Parameters < typeof gpuMetric >[ 3 ] = 'sum' ) => hasReading ( gpuValue ( key , mode )) ?sourceLabel ( readings ?. find ( r => r . id === gpuId ( report ( key , mode ). devices [ 0 ] ?? selectedGpus [ 0 ]))?. source ) :'Unavailable' ; 134const gpuLoad = gpuValue ( 'utilizationPct' , 'mean' ), vram = gpuValue ( 'memoryUsedGb' ), temperature = gpuValue ( 'temperatureC' , 'max' ), power = gpuValue ( 'powerW' ), powerLimit = gpuValue ( 'powerLimitW' ), pcieRx = gpuValue ( 'pcieRxMbs' ); 135const vramTotal = gpuCapacity ( report ( 'memoryUsedGb' ). partial ?report ( 'memoryUsedGb' ). devices :selectedGpus ); 136const singleReading = selectedGpus . length === 1 ?readings ?. find ( r => r . id === gpuId ( selectedGpus [ 0 ])) :undefined ; 137const gen = singleReading ?. pcieGenMax ?? singleReading ?. pcieGen , width = singleReading ?. pcieWidth ; 138const cpu = cpuChoice === 'all' ?data . hardware . cpuLoad :data . hardware . cpus ?. find ( p => p . id === cpuChoice )?. utilizationPct ; 139const requests = data . requests ?? [], last = requests . find ( r => r . state === 'done' ), visibleRequests = showAll ?requests :requests . slice ( 0 , 12 ); 140const throughput = sourceLabel ( data . telemetry ?. throughput ), throughputKnown = throughput !== 'Unavailable' ; 141const writing = [ 'generating' , 'thinking' ]. includes ( data . phase ); 142const decode = throughputKnown ?( writing ?data . outputTps :last ?. tps ) :null ; 143const prefill = throughputKnown ?( data . phase === 'reading' || writing ?data . promptTps :last ?. promptTps ) :null ; 144const contextKnown = [ 'reported' , 'demo' ]. includes ( data . telemetry ?. context ?? '' ) || data . phase === 'reading' && data . prompt . total > 0 ; 145const contextUsed = data . phase === 'reading' ?data . prompt . total :data . context . usedTokens ; 146const contextPct = contextKnown ?percent ( contextUsed , data . context . maxTokens ) :null ; 147const cacheKnown = [ 'engine' , 'demo' ]. includes ( data . expertCache . source ?? '' ); 148const cacheMemory = cacheKnown ?data . expertCache . memoryGb :null ; 149const cachePercent = hasReading ( cacheMemory ) ?percent ( cacheMemory , gpuCapacity ( defaultDevices )) :cacheKnown ?percent ( data . expertCache . used , data . expertCache . total ) :null ; 150const ramPct = percent ( data . hardware . ramUsedGb , data . hardware . ramTotalGb ); 151// The readings strip under the cards: what the GPU used and cost since Strata started, the fan and clock, and the temperatures this PC can give. 152const energyWh = data . hardware . energyWh , fan = gpuValue ( 'fanPct' , 'max' ), clock = gpuValue ( 'clockMhz' , 'max' ); 153const readingsStrip = [ 154hasReading ( energyWh ) ?{ label :'Energy since start' , value :energyWh >= 1000 ?` ${ number ( energyWh / 1000 , 2 )} kWh` :` ${ number ( energyWh , 1 )} Wh` } :null , 155hasReading ( energyWh ) && electricityPrice > 0 ?{ label :'Cost since start' , value :money . format ( energyWh / 1000 * electricityPrice ) } :null , 156hasReading ( fan ) ?{ label :'GPU fan' , value :` ${ number ( fan )} %` } :null , 157hasReading ( clock ) ?{ label :'GPU clock' , value :` ${ number ( clock )} MHz` } :null , 158hasReading ( data . hardware . cpuTempC ) ?{ label :'CPU temperature' , value :` ${ number ( data . hardware . cpuTempC )} °C` } :null , 159hasReading ( data . hardware . ssdTempC ) ?{ label :'SSD temperature' , value :` ${ number ( data . hardware . ssdTempC )} °C` } :null , 160]. filter (( line ) :line is{ label :string ; value :string } => line !== null ); 161const history = data . history , timestamps = history . map ( s => s . t ); 162const historyGpu = ( key :Parameters < typeof gpuMetric >[ 2 ], fallback :'gpuLoad' | 'vramUsedGb' | 'gpuTempC' | 'powerW' | 'pcieRxMbs' , mode :Parameters < typeof gpuMetric >[ 3 ] = 'sum' ) => history . map ( sample => sample . gpus ?gpuMetric ( selectedGpus , sample . gpus , key , mode ) :( sample . gpuIds ?selectedGpus . length === sample . gpuIds . length && selectedGpus . every ( gpu => sample . gpuIds ! . includes ( gpuId ( gpu ))) :gpuChoice === 'all' ) ?sample [ fallback ] :null ); 163const historyCpu = history . map ( sample => cpuChoice === 'all' ?sample . cpuLoad :sample . cpus ?. find ( p => p . id === cpuChoice )?. utilizationPct ); 164const chart = ( label :string , values :( number | null | undefined )[], unit :string , maximum ?:number , tone ?:string ) => < ReferenceSpark label = { tr ( label )} data = { values } unit = { unit } timestamps = { timestamps } maximum = { maximum } tone = { tone }/>; 165const gpuName = multipleGpus ?` ${ selectedGpus . length } GPUs · mean utilization` :selectedGpus [ 0 ]?. name ?? ( selectedInstance && ! selectedInstance . gpuIds . length ?native ?'Automatic GPU placement' :'CPU only · no GPU assigned' :'No GPU detected' ); 166const cpuName = ! selectedCpus . length ?'Processor information unavailable' :selectedCpus . length > 1 ?` ${ selectedCpus . length } processors · ${ selectedCpus . reduce (( n , p ) => n + p . cores , 0 )} cores · ${ selectedCpus . reduce (( n , p ) => n + p . threads , 0 )} threads` :` ${ selectedCpus [ 0 ]?. model ?? 'CPU' } · ${ hardware ?. cpu . topologyKnown === false ? '' : ` ${ selectedCpus [ 0 ]?. cores ?? 0 } cores · ` } ${ selectedCpus [ 0 ]?. threads ?? 0 } threads` ; 167const phase = writing ?'generating' :data . queue . waiting > 0 && data . phase === 'idle' ?'queued' :data . phase ; 168const progress = data . phase === 'reading' ?data . prompt . pct :writing ?percent ( data . generation ?. done , data . generation ?. total ) :0 ; 169const statusDetail = data . phase === 'reading' && data . prompt . total ?` ${ tokens ( data . prompt . done )} / ${ tokens ( data . prompt . total )} tokens · ${ Math . round ( data . prompt . pct )} %` :writing && hasReading ( data . generation ?. done ) ?` ${ tokens ( data . generation . done )} tokens · ${ tps ( data . outputTps )} tok/s` :last ?`Last: ${ tokens ( last . tokensOut )} tokens ${ hasReading ( last . tps ) ? ` at ${ tps ( last . tps )} tok/s` : '' } ` :'' ; 170const cache = data . conversationCache ; 171const reused = requests . filter ( r => hasReading ( r . cachedTokens )); 172const lastRequest = requests . find ( r => r . state === 'done' ); 173const lastReused = hasReading ( lastRequest ?. cachedTokens ) ?lastRequest :null ; 174const reusedTotal = reused . length ?reused . reduce (( n , r ) => n + ( r . cachedTokens ?? 0 ), 0 ) :null ; 175const lastCacheText = hasReading ( cache ?. lastReused ) && hasReading ( cache ?. lastPrompt ) ?` ${ tokens ( cache . lastReused )} of ${ tokens ( cache . lastPrompt )} prompt tokens reused` :lastReused ?` ${ tokens ( lastReused . cachedTokens )} of ${ tokens ( lastReused . tokensIn )} prompt tokens reused` :'Reuse not reported' ; 176const promptSpeed = data . totals . promptMs ?data . totals . uncachedTokens / ( data . totals . promptMs / 1000 ) :null ; 177const outputSpeed = data . totals . decodeMs ?data . totals . tokensOut / ( data . totals . decodeMs / 1000 ) :null ; 178const multipleScope = selection === 'all' && ( runtime ?. instances . length ?? 0 ) > 1 ; 179const chooseInstance = ( id :string ) => { setInstanceSelection ( id ); setGpuSelection ( null ); }; 180const overview = < div className = "stack stack--lg monitor-capture monitor-dashboard" ref = { snapshotRef }> 181{ tr ( frozen ?< header className = "section-toolbar" >< div >< div className = "snapshot__brand-title" >< Brand variant = "lockup" height = { 24 } decorative /></ div >< p className = "small muted" >{ tr ( frozen . modelLabel )} · { tr ( frozen . time )}</ p ></ div ></ header > :null )} 182{ tr ( multipleModels ?< section className = "st-card" >< h2 className = "h4" >{ tr ( "Model performance" )}</ h2 >< div className = "st-tablewrap" >< table className = "st-table native-performance-table" >< thead >< tr >< th >{ tr ( "Model / device" )}</ th >< th >{ tr ( "Generating tok/s" )}</ th >< th >{ tr ( "Reading tok/s" )}</ th >< th >{ tr ( "State" )}</ th >< th >{ tr ( "Active / queued" )}</ th ></ tr ></ thead >< tbody >{ tr ( runtime ?. instances . map ( i => { const recent = ( data . requests ?? []). find ( r => r . instanceId === i . id ); const writing = i . phase === 'generating' || i . phase === 'thinking' , reading = i . phase === 'reading' ; return < tr key = { i . id }>< td >< button className = "text-btn strong" onClick = {() => chooseInstance ( i . id )}>{ tr ( instanceLabel ( i ))}</ button >< small >{ tr ( deviceLabel ( i . gpuIds , inventory ))}</ small ></ td >< td >{ tr ( number ( writing ?i . outputTps :recent ?. tps , 1 ))}< small >{ tr ( writing ?'Now' :recent ?'Last request' :'No request yet' )}</ small ></ td >< td >{ tr ( number ( reading ?i . promptTps :recent ?. promptTps , 0 ))}< small >{ tr ( reading ?'Now' :recent ?'Last request' :'No request yet' )}</ small ></ td >< td >{ tr ( i . phase )}{ tr ( runtime . mode === 'simulated' ?< small >{ tr ( "Illustrative" )}</ small > :null )}</ td >< td >{ tr ( number ( i . active ))} / { tr ( number ( i . queued ))}</ td ></ tr >; }))}</ tbody ></ table ></ div ></ section > :null )} 183{ tr ( multipleModels ?< p className = "xs muted monitor-scope-note" >{ tr ( selectedInstance ?selectedInstance . gpuIds . length ?'Requests, context and speed are scoped to this model. GPU readings include all work on the selected devices.' :'CPU-only model. Requests and context are scoped to this model; system metrics are shared host measurements.' :'Select a model for its context and speed. GPU readings and system RAM are shared host measurements.' )}</ p > :null )} 184< section className = "st-card monitor-state" aria-label = { tr ( "Model state" )} data-snapshot-skip > 185< div className = "monitor-state__head" >< h2 className = "h4" >{ tr ( multipleScope ?'Model activity' :'Model state' )}</ h2 >< div className = "monitor-state__badges" >{ tr (< span className = "st-badge" data-phase = { phase } data-active = "true" >{ tr ( phase === 'reading' ?'Reading' :writing ?'Generating' :phase === 'queued' ?'Queued' :phase === 'error' ?'Error' :phase === 'loading' ?'Loading' :'Idle' )}{ tr ( phase === 'queued' && data . queue . waiting > 0 ?` ( ${ data . queue . waiting } )` :'' )}</ span >)}</ div >< div className = "monitor-device-selectors" >{ tr ( devices . length > 1 ?< Select ariaLabel = { tr ( "Monitor GPU" )} value = { gpuChoice } options = {[ ...( selectedInstance ?[{ value :'assigned' , label :'Assigned GPUs' }] :[]), { value :'all' , label :`All GPUs ( ${ defaultDevices . length } )` }, ...devices . map (( gpu , i ) => ({ value :gpuId ( gpu ), label :`GPU ${ i + 1 } · ${ gpu . name } ` }))]} menuMinWidth = { 340 } onChange = { setGpuSelection }/> :null )}{ tr ( processors . length > 1 ?< Select ariaLabel = { tr ( "Monitor processor" )} value = { cpuChoice } options = {[{ value :'all' , label :`All processors ( ${ processors . length } )` }, ...processors . map (( p , i ) => ({ value :p . id , label :`CPU ${ i + 1 } · ${ p . model } ` }))]} onChange = { setCpuSelection }/> :null )}</ div ></ div > 186< div className = "monitor-state__reading small" >< span >{ tr ( multipleScope ?` ${ number ( data . queue . running )} active · ${ number ( data . queue . waiting )} queued` :data . phase === 'idle' ?'Waiting for a request' :data . phaseLabel )}</ span >< span className = "muted num" >{ tr ( statusDetail )}</ span ></ div > 187{ tr ( ! multipleScope ?< Bar label = { tr ( "Model progress" )} value = { progress ?? 0 } indeterminate = { writing && ! hasReading ( progress )} tone = { data . phase === 'reading' ?'info' :'accent' }/> :null )} 188</ section > 189< div className = "monitor-metrics" > 190{ tr ( ! multipleScope ?< MonitorMetric label = { tr ( "Speed" )} icon = "gauge" value = { number ( decode , 1 )} unit = { hasReading ( decode ) ?'tok/s' :'' } source = { throughput } sub = { writing ?'Decode now' :last ?'Decode last request' :'Decode' } secondary = {< div >< div className = "st-metric__value" >{ tr ( number ( prefill ))}{ tr ( hasReading ( prefill ) ?< span className = "st-metric__unit" >{ tr ( "tok/s" )}</ span > :null )}</ div >< div className = "monitor-metric__sub xs muted" >{ tr ( data . phase === 'reading' ?'Prefill now' :writing ?'Prefill this request' :last ?'Prefill last request' :'Prefill' )}</ div ></ div >} chart = {< ReferenceSpark label = { tr ( "Speed" )} data = { history . map ( s => throughputKnown ?s . outputTps :null )} secondary = {{ data :history . map ( s => throughputKnown ?s . promptTps :null ), label :'Prefill' , tone :'var(--st-chart-prefill)' }} tone = "var(--st-chart-decode)" unit = "tok/s" timestamps = { timestamps }/>}/> :null )} 191< MonitorMetric label = { tr ( "GPU load" )} icon = "gpu" value = { number ( gpuLoad )} unit = { hasReading ( gpuLoad ) ?'%' :'' } source = { gpuSource ( 'utilizationPct' , 'mean' )} sub = { whose ( 'utilizationPct' , 'mean' ) ?? gpuName } chart = { chart ( 'GPU load' , historyGpu ( 'utilizationPct' , 'gpuLoad' , 'mean' ), '%' , 100 )}/> 192< MonitorMetric label = { tr ( shared ?'Shared GPU memory' :'VRAM' )} icon = "layers" value = { number ( vram , 1 )} unit = { hasReading ( vram ) ?vramTotal ?`/ ${ number ( vramTotal , 0 )} GB` :'GB' :'' } source = { gpuSource ( 'memoryUsedGb' )} sub = { whose ( 'memoryUsedGb' ) ?? ( shared ?'Same memory pool as system RAM' :multipleGpus ?'Total across selected GPUs' :cacheKnown && devices . length === 1 ?` ${ number ( data . expertCache . used )} experts cached` :'GPU memory' )} chart = { chart ( shared ?'Shared GPU memory' :'VRAM' , historyGpu ( 'memoryUsedGb' , 'vramUsedGb' ), 'GB' , vramTotal )}/> 193< MonitorMetric label = { tr ( "GPU temp" )} icon = "thermometer" value = { number ( temperature )} unit = { hasReading ( temperature ) ?'°C' :'' } source = { gpuSource ( 'temperatureC' , 'max' )} sub = { whose ( 'temperatureC' , 'max' ) ?? ( multipleGpus ?'Hottest selected GPU' :selectedGpus [ 0 ]?. name ?? ( selectedInstance && ! selectedInstance . gpuIds . length ?native ?'Automatic GPU placement' :'CPU only · no GPU assigned' :'No GPU detected' ))} chart = { chart ( 'GPU temperature' , historyGpu ( 'temperatureC' , 'gpuTempC' , 'max' ), '°C' , 90 , 'var(--st-warn)' )}/> 194< MonitorMetric label = { tr ( "Power" )} icon = "bolt" value = { number ( power )} unit = { hasReading ( power ) ?'W' :'' } source = { gpuSource ( 'powerW' )} sub = { whose ( 'powerW' ) ?? ( hasReading ( powerLimit ) ?`of ${ number ( powerLimit )} W limit` :multipleGpus ?'Total across selected GPUs' :'GPU power draw' )} chart = { chart ( 'GPU power' , historyGpu ( 'powerW' , 'powerW' ), 'W' , powerLimit ?? undefined )}/> 195< MonitorMetric label = { tr ( "PCIe" )} icon = "link" value = { hasReading ( gen ) ?`Gen ${ gen } ` :multipleGpus ?number ( pcieRx , 1 ) :'—' } unit = { hasReading ( gen ) && hasReading ( width ) ?`x ${ width } ` :multipleGpus && hasReading ( pcieRx ) ?'MB/s' :'' } source = { hasReading ( gen ) ?sourceLabel ( singleReading ?. source ) :gpuSource ( 'pcieRxMbs' )} sub = { hasReading ( pcieRx ) ?`To GPU ${ number ( pcieRx , 1 )} MB/s ${ whose ( 'pcieRxMbs' ) ? ` · ${ whose ( 'pcieRxMbs' )} ` : '' } ${ hasReading ( gen ) && hasReading ( singleReading ?. pcieGen ) && singleReading . pcieGen < gen ? ` · idle Gen ${ singleReading . pcieGen } ` : '' } ` :shared ?'Shared memory · no PCIe link' :multipleGpus ?'Total transfer to selected GPUs' :'Transfer to GPU unavailable' } chart = { chart ( 'PCIe transfer' , historyGpu ( 'pcieRxMbs' , 'pcieRxMbs' ), 'MB/s' , undefined , 'var(--st-info)' )}/> 196< MonitorMetric label = { tr ( "CPU" )} icon = "cpu" value = { number ( cpu )} unit = { hasReading ( cpu ) ?'%' :'' } source = { hasReading ( cpu ) ?'Measured' :'Unavailable' } sub = { cpuName } chart = { chart ( 'CPU utilization' , historyCpu , '%' , 100 )}/> 197< MonitorMetric label = { tr ( "Disk read" )} icon = "disk" value = { number ( hasReading ( data . hardware . diskReadGbs ) ?data . hardware . diskReadGbs >= 1 ?data . hardware . diskReadGbs :data . hardware . diskReadGbs * 1024 :null , 1 )} unit = { hasReading ( data . hardware . diskReadGbs ) ?data . hardware . diskReadGbs >= 1 ?'GB/s' :'MB/s' :'' } source = { hasReading ( data . hardware . diskReadGbs ) ?'Measured' :'Unavailable' } sub = { hasReading ( data . hardware . diskWriteMbs ) ?`Write ${ number ( data . hardware . diskWriteMbs , 1 )} MB/s` :'Read throughput' } chart = { chart ( 'Disk read' , history . map ( s => hasReading ( s . diskReadGbs ) ?s . diskReadGbs * 1024 :null ), 'MB/s' , undefined , 'var(--st-info)' )}/> 198</ div > 199{ tr ( readingsStrip . length ?< section className = "st-card monitor-readings" aria-label = { tr ( "Energy and temperature readings" )}>< dl >{ readingsStrip . map ( item => < div key = { item . label }>< dt >{ tr ( item . label )}</ dt >< dd className = "num" >{ item . value }</ dd ></ div >)}</ dl ></ section > :null )} 200< div className = "monitor-context-requests" > 201< section className = "st-card monitor-context" >< h2 className = "h4" >{ tr ( "Context fill" )}</ h2 >< div className = "monitor-context__gauge" >< Gauge value = { contextPct ?? 0 } label = { tr ( hasReading ( contextPct ) ?` ${ Math . round ( contextPct )} %` :'—' )} sub = { contextKnown ?` ${ tokens ( contextUsed )} / ${ contextLabel ( data . context . maxTokens )} ` :selection === 'all' && ( runtime ?. instances . length ?? 0 ) > 1 ?'Select a model to see context' :'No recorded request usage' }/></ div > 202< div className = "monitor-bar-reading" >< span >{ tr ( "Experts in VRAM" )}</ span >< span className = "muted num" >{ tr ( cacheKnown ?` ${ number ( data . expertCache . used )} ${ hasReading ( cacheMemory ) ? ` · ${ number ( cacheMemory , 1 )} GB` : '' } ` :'—' )}</ span ></ div >< ReadingBar label = { tr ( "Experts in VRAM" )} value = { cachePercent }/> 203< div className = "monitor-bar-reading" >< span >{ tr ( "System RAM" )}</ span >< span className = "muted num" >{ tr ( hasReading ( data . hardware . ramUsedGb ) ?` ${ number ( data . hardware . ramUsedGb , 1 )} / ${ number ( data . hardware . ramTotalGb )} GB` :'—' )}</ span ></ div >< ReadingBar label = { tr ( "System RAM" )} value = { ramPct } tone = { hasReading ( ramPct ) && ramPct > 92 ?'danger' :'accent' }/> 204< div className = "monitor-bar-reading" >< span >{ tr ( "GPU temperature" )}</ span >< span className = "muted num" >{ tr ( number ( temperature ))}{ tr ( hasReading ( temperature ) ?' °C' :'' )}</ span ></ div >< ReadingBar label = { tr ( "GPU temperature" )} value = { temperature } tone = "warn" /> 205</ section > 206< section className = "st-card monitor-requests" >< div className = "section-toolbar" >< h2 className = "h4" >{ tr ( "Recent requests" )}</ h2 >{ tr ( requests . length > 12 ?< Btn size = "sm" onClick = {() => setShowAll ( ! showAll )}>{ tr ( showAll ?'Show fewer' :`Show all ( ${ requests . length } )` )}</ Btn > :null )}</ div > 207< div className = "st-tablewrap monitor-request-table" data-expanded = { showAll }>< table className = "st-table" >< thead >< tr >< th >{ tr ( "Time" )}</ th >< th >{ tr ( "Status" )}</ th >{ tr ( multipleModels ?< th >{ tr ( "Model" )}</ th > :null )}< th className = "num" >{ tr ( "Prompt" )}</ th >< th className = "num" >{ tr ( "Reused" )}</ th >< th className = "num" >{ tr ( "Output" )}</ th >< th className = "num" >{ tr ( "Tok/s" )}</ th >< th className = "num" title = { tr ( "Experts already in GPU memory; PCIe share is shown separately when reported." )}>{ tr ( "VRAM hit rate" )}</ th >< th className = "num" >{ tr ( "Duration" )}</ th ></ tr ></ thead >< tbody >{ tr ( visibleRequests . length ?visibleRequests . map ( r => < tr key = { r . id }>< td >{ tr ( new Date ( r . at ). toLocaleTimeString ( localeTag (), { hour :'2-digit' , minute :'2-digit' , second :'2-digit' }))}</ td >< td >< span className = "request-status" data-state = { r . state }>{ tr ( requestStatus ( r ))}</ span >{ tr ( r . usageSource === 'demo' ?< span className = "monitor-request-source xs muted" >{ tr ( "Illustrative" )}</ span > :null )}</ td >{ tr ( multipleModels ?< td >< span className = "xs" >{ tr ( r . model )}</ span ></ td > :null )}< td className = "num" >{ tr ( number ( r . tokensIn ))}</ td >< td className = "num" >{ tr ( number ( r . cachedTokens ))}</ td >< td className = "num" >{ tr ( number ( r . tokensOut ))}</ td >< td className = "num" >{ tr ( number ( r . tps , 1 ))}</ td >< td className = "num" >{ tr ( hasReading ( r . hitRate ) ?` ${ number ( r . hitRate * 100 , 1 )} %` :'—' )}{ tr ( hasReading ( r . pcieShare ) && r . pcieShare > 0 ?< span className = "xs muted" > + { tr ( number ( r . pcieShare * 100 , 1 ))}{ tr ( "% PCIe" )}</ span > :null )}</ td >< td className = "num" >{ tr ( r . durationMs ?duration ( r . durationMs ) :'—' )}</ td ></ tr >) :< tr >< td colSpan = { multipleModels ?9 :8 } className = "muted" >{ tr ( "No requests yet" )}</ td ></ tr >)}</ tbody ></ table ></ div > 208{ /* One request is already the row above: the aggregate sentence would only 209restate it, and in English it also read “In 1 requests”. Show it from two 210requests on, where it carries information the table cannot. */ } 211{ tr ( data . totals . requests > 1 ?< p className = "small muted monitor-request-totals" >{ requestSummary ({ requests :data . totals . requests , output :outputSpeed , reading :promptSpeed , reused :data . totals . cachedTokens }, { number, tokens})}</ p > :null )} 212</ section > 213</ div > 214< section className = "st-card monitor-cache" data-snapshot-skip >< div className = "section-toolbar" >< h2 className = "h4" >{ tr ( "Conversation cache" )}</ h2 >{ tr ( lastReused ?< span className = "small muted" >{ tr ( "{0} of {1} requests reused prompt tokens" , [ number ( cache ?. requestsReused ?? reused . filter ( r => ( r . cachedTokens ?? 0 ) > 0 ). length ), number ( cache ?. requests ?? requests . length )])}</ span > :null )}</ div > 215{ tr ( cache ?. enabled ?< div className = "monitor-cache-bars" >< div >< div className = "monitor-bar-reading" >< span >{ tr ( "Parked conversations" )}</ span >< span className = "muted num" >{ tr ( number ( cache . parked ))} / { tr ( number ( cache . slots ))}</ span ></ div >< ReadingBar label = { tr ( "Parked conversations" )} value = { percent ( cache . parked , cache . slots )}/></ div >< div >< div className = "monitor-bar-reading" >< span >{ tr ( "Their memory (RAM)" )}</ span >< span className = "muted num" >{ tr ( number ( cache . memoryGb , 1 ))} / { tr ( number ( cache . budgetGb , 1 ))}{ tr ( " GB" )}</ span ></ div >< ReadingBar label = { tr ( "Conversation cache memory" )} value = { percent ( cache . memoryGb , cache . budgetGb )}/></ div ></ div > :null )} 216< dl className = "monitor-cache-facts" >< div >< dt >{ tr ( "Last request" )}</ dt >< dd >{ tr ( lastCacheText )}</ dd ></ div >< div >< dt >{ tr ( "Reused since start" )}</ dt >< dd >{ tr ( hasReading ( reusedTotal ) ?` ${ tokens ( data . totals . cachedTokens )} tokens` :'—' )}</ dd ></ div >{ tr ( cache ?. enabled ?<>< div >< dt >{ tr ( "Parked / restored" )}</ dt >< dd >{ tr ( number ( cache . parks ))} / { tr ( number ( cache . restores ))}{ tr ( cache . evictions ?` · ${ number ( cache . evictions )} evicted` :'' )}</ dd ></ div >{ tr ( cache . lastEvent ?< div >< dt >{ tr ( "Last switch" )}</ dt >< dd >{ tr ( cache . lastEvent === 'parked' ?'Parked' :'Restored' )} { tr ( tokens ( cache . lastTokens ))}{ tr ( " tokens" )}{ tr ( cache . lastAt ?` · ${ new Date ( cache . lastAt * 1000 ). toLocaleTimeString ( localeTag ())} ` :'' )}</ dd ></ div > :null )}</> :null )}</ dl > 217< p className = "small muted" >{ tr ( cache ?. enabled ?'Parked conversations resume from their saved state. The oldest is removed when the cache fills.' :lastReused ?'Follow-up requests can reuse the previous prompt’s cached tokens.' :'Cache details appear when the engine reports prompt reuse.' )}</ p > 218</ section > 219{ tr ( data . mcp ?. servers . length ?< section className = "st-card monitor-mcp" >< div className = "section-toolbar" >< h2 className = "h4" >{ tr ( "MCP servers" )}</ h2 >< span className = "small muted" >{ tr ( "{0} tools · {1} of {2} servers connected" , [ number ( data . mcp . tools ), number ( data . mcp . servers . filter ( server => [ 'ready' , 'stopped' ]. includes ( server . state )). length ), number ( data . mcp . servers . length )])}</ span ></ div >{ tr ( data . mcp . servers . map ( server => < div key = { server . name }>< div className = "row row--between" >< strong >{ server . name }</ strong >< span className = "small muted" >{ tr ({ ready :'Connected' , starting :'Starting' , failed :'Failed' , stopped :'Stopped' , idle :'Waiting' }[ server . state ] ?? server . state )}</ span ></ div >< p className = "xs muted" >{ server . transport }{ tr ( server . transport ?' · ' :'' )}{ tr ( server . tools . length )}{ tr ( " tools" )}{ tr ( server . info ?. name ?` · ${ server . info . name } ${ server . info . version ? ` ${ server . info . version } ` : '' } ` :'' )}</ p >{ tr ( server . error ?< p className = "small inline-error" >{ tr ( server . error )}</ p > :null )}< div className = "monitor-mcp-tools" >{ tr ( server . tools . map ( tool => < span key = { tool . name } title = { tr ( tool . description )} className = "st-badge" >{ tool . name }</ span >))}</ div ></ div >))}</ section > :null )} 220</ div >; 221return < Screen width = "wide" plainHeader title = { tr ( "Monitor" )} titleDetail = { multipleModels ?< Select ariaLabel = { tr ( "Monitor model" )} value = { selection } options = {[{ value :'all' , label :`All models ( ${ runtime ?. instances . length ?? 0 } )` }, ...( runtime ?. instances ?? []). map ( i => ({ value :i . id , label :` ${ instanceLabel ( i )} · ${ deviceLabel ( i . gpuIds , inventory )} ` }))]} onChange = { chooseInstance }/> :selectedInstance ?instanceLabel ( selectedInstance ) :'No model loaded' } actions = {< IconBtn name = "image" title = { tr ( saving ?'Preparing screenshot…' :'Save Monitor screenshot' )} disabled = { saving } onClick = {() => void saveScreenshot ()}/>}>{ tr ( saveError ?< p className = "inline-error" role = "alert" >{ tr ( saveError )}</ p > :null )}{ tr ( overview )}< SnapshotDialog open = { snapshotOpen } data = { screenshot } pending = { saving } error = { saveError } onClose = {() => setSnapshotOpen ( false )} onRetry = {() => void saveScreenshot ()}/></ Screen >; 222}