@@ -63,6 +63,9 @@ const appendGraphData = (dataArray: number[], newValue: number): number[] => {
6363 return updated
6464}
6565
66+ const STALE_STATS_THRESHOLD_MS = 5000
67+ const STALE_STATS_PUSH_INTERVAL_MS = 1000
68+
6669const mapPowerStateFromStateEvent = (
6770 data : Archon . Websocket . v0 . WSStateEvent ,
6871) : Archon . Websocket . v0 . PowerState => {
@@ -101,6 +104,8 @@ export function useServerManageCoreRuntime(options: UseServerManageCoreRuntimeOp
101104 const ramData = ref < number [ ] > ( [ ] )
102105
103106 let uptimeIntervalId : ReturnType < typeof setInterval > | null = null
107+ let staleStatsTimeoutId : ReturnType < typeof setTimeout > | null = null
108+ let staleStatsIntervalId : ReturnType < typeof setInterval > | null = null
104109
105110 const markBackupCancelled =
106111 options . markBackupCancelled ??
@@ -183,6 +188,43 @@ export function useServerManageCoreRuntime(options: UseServerManageCoreRuntimeOp
183188 }
184189 }
185190
191+ const clearStaleStatsTimers = ( ) => {
192+ if ( staleStatsTimeoutId ) {
193+ clearTimeout ( staleStatsTimeoutId )
194+ staleStatsTimeoutId = null
195+ }
196+ if ( staleStatsIntervalId ) {
197+ clearInterval ( staleStatsIntervalId )
198+ staleStatsIntervalId = null
199+ }
200+ }
201+
202+ const pushZeroStats = ( ) => {
203+ if ( ! shouldProcessEvent ( ) ) return
204+ cpuData . value = appendGraphData ( cpuData . value , 0 )
205+ ramData . value = appendGraphData ( ramData . value , 0 )
206+ stats . value = {
207+ current : {
208+ ...stats . value . current ,
209+ cpu_percent : 0 ,
210+ ram_usage_bytes : 0 ,
211+ } ,
212+ past : { ...stats . value . current } ,
213+ graph : {
214+ cpu : cpuData . value ,
215+ ram : ramData . value ,
216+ } ,
217+ }
218+ }
219+
220+ const armStaleStatsWatchdog = ( ) => {
221+ clearStaleStatsTimers ( )
222+ staleStatsTimeoutId = setTimeout ( ( ) => {
223+ pushZeroStats ( )
224+ staleStatsIntervalId = setInterval ( pushZeroStats , STALE_STATS_PUSH_INTERVAL_MS )
225+ } , STALE_STATS_THRESHOLD_MS )
226+ }
227+
186228 const updatePowerState = (
187229 state : Archon . Websocket . v0 . PowerState ,
188230 details ?: { oom_killed ?: boolean ; exit_code ?: number } ,
@@ -209,6 +251,7 @@ export function useServerManageCoreRuntime(options: UseServerManageCoreRuntimeOp
209251 }
210252
211253 const handleStats = ( data : Archon . Websocket . v0 . WSStatsEvent ) => {
254+ armStaleStatsWatchdog ( )
212255 updateStats ( {
213256 cpu_percent : data . cpu_percent ,
214257 ram_usage_bytes : data . ram_usage_bytes ,
@@ -280,6 +323,7 @@ export function useServerManageCoreRuntime(options: UseServerManageCoreRuntimeOp
280323 }
281324
282325 stopUptimeTicker ( )
326+ clearStaleStatsTimers ( )
283327 connectedSocketServerId . value = null
284328 isConnected . value = false
285329 isWsAuthIncorrect . value = false
0 commit comments