@@ -52,6 +52,35 @@ function systemStats() {
5252 return { totalMem, usedMem, memPct, load1, load5, load15, cpuCount, cpuPct, disk } ;
5353}
5454
55+ // keep in sync with the OnCalendar= line in steambrew-www-swap.timer on the server
56+ const RESTART_HOUR_UTC = 4 ;
57+ const RESTART_MINUTE_UTC = 17 ;
58+ const LOCAL_TZ = 'America/Halifax' ;
59+
60+ function formatUtc ( date : Date ) {
61+ return date . toISOString ( ) . replace ( 'T' , ' ' ) . replace ( / \. \d + Z $ / , ' UTC' ) ;
62+ }
63+
64+ function formatLocal ( date : Date ) {
65+ return `${ date . toLocaleString ( 'en-US' , { timeZone : LOCAL_TZ , dateStyle : 'medium' , timeStyle : 'medium' } ) } (${ LOCAL_TZ } )` ;
66+ }
67+
68+ function formatDuration ( totalSeconds : number ) {
69+ const d = Math . floor ( totalSeconds / 86400 ) ;
70+ const h = Math . floor ( ( totalSeconds % 86400 ) / 3600 ) ;
71+ const m = Math . floor ( ( totalSeconds % 3600 ) / 60 ) ;
72+ const s = Math . floor ( totalSeconds % 60 ) ;
73+ return [ d && `${ d } d` , ( d || h ) && `${ h } h` , ( d || h || m ) && `${ m } m` , `${ s } s` ] . filter ( Boolean ) . join ( ' ' ) ;
74+ }
75+
76+ function nextScheduledRestart ( now : Date ) {
77+ const next = new Date ( Date . UTC ( now . getUTCFullYear ( ) , now . getUTCMonth ( ) , now . getUTCDate ( ) , RESTART_HOUR_UTC , RESTART_MINUTE_UTC , 0 ) ) ;
78+ if ( next . getTime ( ) <= now . getTime ( ) ) {
79+ next . setUTCDate ( next . getUTCDate ( ) + 1 ) ;
80+ }
81+ return next ;
82+ }
83+
5584export function GET ( ) {
5685 const now = Date . now ( ) / 1000 ;
5786 const www = parseLog ( LOG_FILES . www ) ;
@@ -66,9 +95,20 @@ export function GET() {
6695 all . filter ( e => e . status >= min && e . status < max ) . length ;
6796 const sys = systemStats ( ) ;
6897
98+ const nowDate = new Date ( now * 1000 ) ;
99+ const startedAt = new Date ( now * 1000 - process . uptime ( ) * 1000 ) ;
100+ const nextRestart = nextScheduledRestart ( nowDate ) ;
101+
69102 const text = `steambrew.app — live stats
70103updated ${ new Date ( ) . toUTCString ( ) }
71104
105+ process
106+ uptime ${ formatDuration ( process . uptime ( ) ) }
107+ started ${ formatUtc ( startedAt ) }
108+ ${ formatLocal ( startedAt ) }
109+ next restart ${ formatUtc ( nextRestart ) }
110+ ${ formatLocal ( nextRestart ) } (±5m jitter)
111+
72112server
73113 cpu ${ sys . cpuPct } % (${ sys . cpuCount } cores, load ${ sys . load1 . toFixed ( 2 ) } / ${ sys . load5 . toFixed ( 2 ) } / ${ sys . load15 . toFixed ( 2 ) } )
74114 memory ${ fmt ( sys . usedMem ) } / ${ fmt ( sys . totalMem ) } (${ sys . memPct } %)
0 commit comments