🎉 init: impl dashboard overview

This commit is contained in:
2026-08-23 17:36:27 +08:00
parent ce5c3c5773
commit f090c7481b
19 changed files with 2366 additions and 16 deletions
+64
View File
@@ -0,0 +1,64 @@
export function formatBytes(bytes?: number, decimals = 2): string {
if (bytes === undefined || bytes === null || isNaN(bytes) || bytes === 0) return '0 B'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k))
const idx = Math.min(i, sizes.length - 1)
return `${parseFloat((bytes / Math.pow(k, idx)).toFixed(dm))} ${sizes[idx]}`
}
export function formatSpeed(bps?: number, decimals = 2): string {
if (bps === undefined || bps === null || isNaN(bps) || bps === 0) return '0 B/s'
return `${formatBytes(bps, decimals)}/s`
}
export function formatPPS(pps?: number): string {
if (pps === undefined || pps === null || isNaN(pps) || pps === 0) return '0 PPS'
if (pps >= 1_000_000) {
return `${(pps / 1_000_000).toFixed(2)} M PPS`
}
if (pps >= 1_000) {
return `${(pps / 1_000).toFixed(2)} K PPS`
}
return `${Math.round(pps)} PPS`
}
/**
* 格式化时间延迟(核心协议与 Java 监控全部输出纳秒 ns)
* @param nanoDelay 纳秒 (ns)
*/
export function formatNanoDelay(nanoDelay?: number): string {
if (nanoDelay === undefined || nanoDelay === null || isNaN(nanoDelay) || nanoDelay <= 0) {
return '0 ns'
}
if (nanoDelay >= 1_000_000_000) {
return `${(nanoDelay / 1_000_000_000).toFixed(2)} s`
}
if (nanoDelay >= 1_000_000) {
return `${(nanoDelay / 1_000_000).toFixed(2)} ms`
}
if (nanoDelay >= 1_000) {
return `${(nanoDelay / 1_000).toFixed(1)} μs`
}
return `${Math.round(nanoDelay)} ns`
}
/**
* 格式化背板延迟(以微秒/纳秒为主要显示单位)
* @param nanoTime 纳秒 (ns)
*/
export function formatBackplaneDelay(nanoTime?: number): string {
if (nanoTime === undefined || nanoTime === null || isNaN(nanoTime) || nanoTime <= 0) {
return '0.0 μs'
}
if (nanoTime >= 1_000_000) {
return `${(nanoTime / 1_000_000).toFixed(2)} ms`
}
return `${(nanoTime / 1_000).toFixed(1)} μs`
}
export function formatPercent(rate?: number): string {
if (rate === undefined || rate === null || isNaN(rate)) return '0.0%'
return `${(rate * 100).toFixed(2)}%`
}