@@ -8,9 +8,7 @@ const els = {
88 sslBody : ( ) => document . getElementById ( 'sslBody' )
99} ;
1010
11- function bytes ( v ) { if ( v === 0 ) return '0B' ; if ( ! v ) return '-' ; const k = 1000 ; const u = [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ] ; const i = Math . floor ( Math . log ( v ) / Math . log ( k ) ) ; return ( v / Math . pow ( k , i ) ) . toFixed ( i ?1 :0 ) + u [ i ] ; }
12- // 通用进位:从 KB/MB 起始单位自动进位到 KB/MB/GB/TB,与 bytes() 风格一致 (1000 进位)
13- function humanAuto ( v , startIdx = 0 ) { if ( v == null || isNaN ( v ) ) return '-' ; const units = [ 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ] ; let val = v ; let i = startIdx ; while ( val >= 1000 && i < units . length - 1 ) { val /= 1000 ; i ++ ; } return ( i > startIdx ? val . toFixed ( 1 ) : val . toFixed ( 0 ) ) + units [ i ] ; }
11+ // (清理) 已移除 bytes / humanAuto 等未使用的通用进位函数
1412// 最小单位 MB:
1513function humanMinMBFromKB ( kb ) { if ( kb == null || isNaN ( kb ) ) return '-' ; // 输入单位: KB
1614 let mb = kb / 1000 ; const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( mb >= 1000 && i < units . length - 1 ) { mb /= 1000 ; i ++ ; }
@@ -25,8 +23,7 @@ function humanRateMinMBFromB(bytes){ if(bytes==null||isNaN(bytes)) return '-'; i
2523function humanMinKBFromB ( bytes ) { if ( bytes == null || isNaN ( bytes ) ) return '-' ; // 输入单位: B; 最小单位 KB
2624 let kb = bytes / 1000 ; const units = [ 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( kb >= 1000 && i < units . length - 1 ) { kb /= 1000 ; i ++ ; }
2725 const out = kb >= 100 ? kb . toFixed ( 0 ) : kb . toFixed ( 1 ) ; return out + units [ i ] ; }
28- function pct ( v ) { return ( v || 0 ) . toFixed ( 0 ) + '%' ; }
29- function clsBy ( v ) { return v >= 90 ?'danger' :v >= 80 ?'warn' :'ok' ; }
26+ // (清理) pct / clsBy 已不再使用
3027function humanAgo ( ts ) { if ( ! ts ) return '-' ; const s = Math . floor ( ( Date . now ( ) / 1000 - ts ) ) ; const m = Math . floor ( s / 60 ) ; return m > 0 ? m + ' 分钟前' :'几秒前' ; }
3128function num ( v ) { return ( typeof v === 'number' && ! isNaN ( v ) ) ? v : '-' ; }
3229
@@ -88,9 +85,8 @@ function renderServers(){
8885 const online = s . online4 || s . online6 ;
8986 const proto = online ? ( s . online4 && s . online6 ? '双栈' : s . online4 ? 'IPv4' :'IPv6' ) : '离线' ;
9087 const statusPill = online ? `<span class="pill on">${ proto } </span>` : `<span class="pill off">${ proto } </span>` ;
91- const cpuCls = clsBy ( s . cpu ) ;
92- const memPct = s . memory_total ? ( s . memory_used / s . memory_total * 100 ) :0 ; const memCls = clsBy ( memPct ) ;
93- const hddPct = s . hdd_total ? ( s . hdd_used / s . hdd_total * 100 ) :0 ; const hddCls = clsBy ( hddPct ) ;
88+ const memPct = s . memory_total ? ( s . memory_used / s . memory_total * 100 ) :0 ;
89+ const hddPct = s . hdd_total ? ( s . hdd_used / s . hdd_total * 100 ) :0 ;
9490 const monthInBytes = ( s . network_in - s . last_network_in ) || 0 ; // 原始: B
9591 const monthOutBytes = ( s . network_out - s . last_network_out ) || 0 ;
9692 const monthIn = humanMinMBFromB ( monthInBytes ) ; // 最小单位 MB
@@ -133,7 +129,7 @@ function renderServers(){
133129 } ) ;
134130 } ) ;
135131
136- // 仪表盘无需 drawSparks
132+ // 仪表盘无需历史 spark 小图
137133}
138134// 生成仪表盘 (圆形 conic-gradient)
139135function gaugeHTML ( type , val ) {
@@ -159,8 +155,8 @@ function renderServersCards(){
159155 const online = s . online4 || s . online6 ;
160156 const proto = online ? ( s . online4 && s . online6 ? '双栈' : s . online4 ? 'IPv4' :'IPv6' ) : '离线' ;
161157 const pill = `<span class="status-pill ${ online ?'on' :'off' } ">${ proto } </span>` ;
162- const memPct = s . memory_total ? ( s . memory_used / s . memory_total * 100 ) :0 ;
163- const hddPct = s . hdd_total ? ( s . hdd_used / s . hdd_total * 100 ) :0 ;
158+ const memPct = s . memory_total ? ( s . memory_used / s . memory_total * 100 ) :0 ;
159+ const hddPct = s . hdd_total ? ( s . hdd_used / s . hdd_total * 100 ) :0 ;
164160 // 月流量(移动端)并应用 500GB 阈值配色逻辑
165161 const monthInBytes = ( s . network_in - s . last_network_in ) || 0 ; // B
166162 const monthOutBytes = ( s . network_out - s . last_network_out ) || 0 ;
@@ -444,32 +440,7 @@ window.addEventListener('resize', ()=>{
444440 renderSSLCards ( ) ;
445441} ) ;
446442
447- // 绘制小型折线 (sparklines)
448- function drawSparks ( ) {
449- const els = document . querySelectorAll ( '.spark' ) ;
450- els . forEach ( div => {
451- // 若已有canvas跳过重建
452- let canvas = div . querySelector ( 'canvas' ) ;
453- if ( ! canvas ) { canvas = document . createElement ( 'canvas' ) ; div . appendChild ( canvas ) ; }
454- const key = div . getAttribute ( 'data-key' ) ;
455- const metric = div . getAttribute ( 'data-metric' ) ;
456- const hist = ( S . metricHist [ key ] && S . metricHist [ key ] [ metric ] ) ? S . metricHist [ key ] [ metric ] :[ ] ;
457- const W = 80 , H = 26 ; canvas . width = W ; canvas . height = H ; const ctx = canvas . getContext ( '2d' ) ;
458- ctx . clearRect ( 0 , 0 , W , H ) ;
459- div . classList . add ( 'spark-ready' ) ;
460- if ( hist . length < 2 ) { ctx . fillStyle = 'var(--text-dim)' ; ctx . font = '10px system-ui' ; ctx . fillText ( '-' , W / 2 - 3 , H / 2 + 3 ) ; return ; }
461- // 硬盘与 CPU/内存保持一致的折线显示(去掉低波动迷你条特殊样式)
462- const max = Math . max ( ...hist ) ; const min = Math . min ( ...hist ) ; const range = Math . max ( 1 , max - min ) ;
463- const step = W / ( hist . length - 1 ) ;
464- // 线颜色
465- let color = '#3b82f6' ; if ( metric === 'mem' ) color = '#10b981' ; else if ( metric === 'hdd' ) color = '#f59e0b' ;
466- ctx . strokeStyle = color ; ctx . lineWidth = 1.3 ; ctx . beginPath ( ) ;
467- hist . forEach ( ( v , i ) => { const x = i * step ; const y = H - ( ( v - min ) / range ) * ( H - 4 ) - 2 ; if ( i === 0 ) ctx . moveTo ( x , y ) ; else ctx . lineTo ( x , y ) ; } ) ;
468- ctx . stroke ( ) ;
469- // 当前值点
470- const last = hist [ hist . length - 1 ] ; const lx = W - 1 ; const ly = H - ( ( last - min ) / range ) * ( H - 4 ) - 2 ; ctx . fillStyle = color ; ctx . beginPath ( ) ; ctx . arc ( lx , ly , 2 , 0 , Math . PI * 2 ) ; ctx . fill ( ) ;
471- } ) ;
472- }
443+ // (清理) drawSparks 已移除
473444
474445// 负载折线图 (load1 历史)
475446function drawLoadChart ( key ) {
0 commit comments