Serverpuls: Admin-Seite mit Verlauf und Warnungen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae905a5d9b
commit
ec740ca970
12 files changed
+749
-3
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// Reine Format-Helfer fuer die Serverpuls-Seite (kein React, unter Node testbar).
|
||||
const nf = (digits) =>
|
||||
new Intl.NumberFormat('de-DE', { minimumFractionDigits: 0, maximumFractionDigits: digits })
|
||||
|
||||
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
|
||||
|
||||
export function formatBytes(n) {
|
||||
if (n === null || n === undefined || Number.isNaN(Number(n))) return '–'
|
||||
let v = Math.abs(Number(n))
|
||||
if (v < 1) return '0 B'
|
||||
let i = 0
|
||||
while (v >= 1024 && i < UNITS.length - 1) {
|
||||
v /= 1024
|
||||
i += 1
|
||||
}
|
||||
const sign = n < 0 ? '−' : ''
|
||||
return `${sign}${nf(i === 0 ? 0 : 1).format(v)} ${UNITS[i]}`
|
||||
}
|
||||
|
||||
export function formatDelta(pct) {
|
||||
if (pct === null || pct === undefined || Number.isNaN(Number(pct))) {
|
||||
return { text: '–', dir: 'flat' }
|
||||
}
|
||||
const rounded = Math.round(Number(pct) * 10) / 10
|
||||
if (rounded === 0) return { text: '0 %', dir: 'flat' }
|
||||
const sign = rounded > 0 ? '+' : '−'
|
||||
return { text: `${sign}${nf(1).format(Math.abs(rounded))} %`, dir: rounded > 0 ? 'up' : 'down' }
|
||||
}
|
||||
|
||||
export const STALE_MS = 15 * 60 * 1000
|
||||
|
||||
export function ageLabel(ts, now = Date.now()) {
|
||||
if (ts === null || ts === undefined) return { text: 'keine Messung', stale: true }
|
||||
const diff = Math.max(0, now - ts)
|
||||
const min = Math.floor(diff / 60000)
|
||||
let text
|
||||
if (min < 1) text = 'gerade eben'
|
||||
else if (min < 60) text = `vor ${min} Min.`
|
||||
else if (min < 1440) text = `vor ${Math.floor(min / 60)} Std.`
|
||||
else text = `vor ${Math.floor(min / 1440)} T.`
|
||||
return { text, stale: diff > STALE_MS }
|
||||
}
|
||||
|
||||
// RAM: value ist FREIER Speicher, belegt = 1 - frei/gesamt (in Prozent).
|
||||
export function usedPct(free, total) {
|
||||
if (free === null || free === undefined || !total) return null
|
||||
return Math.round((1 - free / total) * 1000) / 10
|
||||
}
|
||||
|
||||
export function formatPct(v, digits = 1) {
|
||||
if (v === null || v === undefined) return '–'
|
||||
return `${nf(digits).format(v)} %`
|
||||
}
|
||||
|
||||
export function formatNumber(v, digits = 2) {
|
||||
if (v === null || v === undefined) return '–'
|
||||
return nf(digits).format(v)
|
||||
}
|
||||
Reference in new issue
Block a user