- 采集器上报 backup_root/usage/quota(加性字段),API 用 BACKUP_HOST_ROOT 校验并分别降级占用/配额 - 页面配额行改为备份占用 X / 配额 50 GB,4 条告警改用备份口径,解除本页归档依赖 - logical-backup.sh 预检按字节清理(保留最新、空间不足零删除),dump 后复查保护新批次 - backup_layout 写入 KB_BACKUP_QUOTA_BYTES;--show 输出根占用;新增 prune 工具与自检
This commit is contained in:
+43
-50
@@ -1,9 +1,7 @@
|
||||
// 「存储与备份」只读摘要的纯逻辑:数据源只有两个只读接口——
|
||||
// /api/v1/backup-schedule/inventory (宿主每 5 分钟上报的元数据快照)
|
||||
// /api/v1/library/storage (归档库自身的占用与配额)
|
||||
// 「存储与备份」只读摘要的纯逻辑:唯一数据源是宿主采集器快照
|
||||
// /api/v1/backup-schedule/inventory (批次、备份根占用、配额与文件系统容量)
|
||||
// 页面不提供任何写操作。读不到的量一律留空("主机未上报" / "—"),不用 0 冒充。
|
||||
import type { BackupInventory, BackupInventoryBatch } from './backupInventory'
|
||||
import type { LibraryStorage } from './librarySnapshots'
|
||||
|
||||
// 阈值(与 docs/STORAGE_BACKUP_READONLY_API.md 的「页面口径」一致):
|
||||
// 磁盘:可用空间 < 5% 红,< 10% 黄
|
||||
@@ -159,11 +157,7 @@ export interface SummaryCard {
|
||||
const lastReportNote = (inventory: BackupInventory): string =>
|
||||
`上次上报 ${formatWhen(inventory.metadata.collected_at) || UNKNOWN}`
|
||||
|
||||
export function summaryCards(
|
||||
inventory: BackupInventory | null,
|
||||
archive: LibraryStorage | null,
|
||||
archiveFailed: boolean
|
||||
): SummaryCard[] {
|
||||
export function summaryCards(inventory: BackupInventory | null): SummaryCard[] {
|
||||
const state = hostState(inventory)
|
||||
const facts = state === 'ready' || state === 'incomplete'
|
||||
const sizes = state === 'ready'
|
||||
@@ -181,7 +175,20 @@ export function summaryCards(
|
||||
const diskKnown = sizes && Boolean(capacity?.measured) && (capacity?.total_bytes ?? 0) > 0
|
||||
const availablePercent = diskKnown ? Math.round((capacity!.available_bytes / capacity!.total_bytes) * 100) : 0
|
||||
|
||||
const archiveKnown = Boolean(archive?.available) && !archiveFailed
|
||||
const usage = inventory?.usage
|
||||
const usageKnown =
|
||||
facts && Boolean(usage?.measured) && usage?.actual_bytes !== null && usage?.actual_bytes !== undefined
|
||||
const quotaBytes = inventory?.quota_bytes
|
||||
const quotaKnown = usageKnown && (quotaBytes ?? 0) > 0
|
||||
const backupNote = !pending
|
||||
? UNKNOWN
|
||||
: !facts
|
||||
? hostNote
|
||||
: usageKnown
|
||||
? quotaKnown
|
||||
? `配额 ${formatSize(quotaBytes)}`
|
||||
: inventory!.quota_error || '配额未上报'
|
||||
: usage?.error || '本次上报不完整'
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -207,17 +214,11 @@ export function summaryCards(
|
||||
unknown: !recent,
|
||||
},
|
||||
{
|
||||
key: 'archive',
|
||||
label: '归档占用',
|
||||
value: archiveKnown ? formatSize(archive!.capacity.current_bytes) : UNKNOWN,
|
||||
note: archiveFailed
|
||||
? '归档读取失败'
|
||||
: !archive || !archive.available
|
||||
? '归档不可用'
|
||||
: archive.capacity.configured
|
||||
? `配额 ${formatSize(archive.capacity.budget_bytes)}`
|
||||
: '配额未设置',
|
||||
unknown: !archiveKnown,
|
||||
key: 'backup',
|
||||
label: '备份占用',
|
||||
value: usageKnown ? formatSize(usage!.actual_bytes) : facts ? UNKNOWN : hostValue,
|
||||
note: backupNote,
|
||||
unknown: !usageKnown,
|
||||
},
|
||||
{
|
||||
key: 'disk',
|
||||
@@ -244,23 +245,21 @@ export interface SummaryAlert {
|
||||
export interface StorageFacts {
|
||||
diskAvailableBytes: number | null
|
||||
diskTotalBytes: number | null
|
||||
archiveUsedBytes: number | null
|
||||
archiveBudgetBytes: number | null
|
||||
backupUsedBytes: number | null
|
||||
backupQuotaBytes: number | null
|
||||
}
|
||||
|
||||
export function storageFacts(
|
||||
inventory: BackupInventory | null,
|
||||
archive: LibraryStorage | null,
|
||||
archiveFailed: boolean
|
||||
): StorageFacts {
|
||||
export function storageFacts(inventory: BackupInventory | null): StorageFacts {
|
||||
const capacity = inventory?.capacity
|
||||
const diskKnown = hostState(inventory) === 'ready' && Boolean(capacity?.measured) && (capacity?.total_bytes ?? 0) > 0
|
||||
const archiveCapacity = archive?.available && !archiveFailed ? archive.capacity : null
|
||||
const usage = inventory?.usage
|
||||
const used = usage?.measured && usage.actual_bytes !== null ? usage.actual_bytes : null
|
||||
const quota = inventory?.quota_bytes ?? null
|
||||
return {
|
||||
diskAvailableBytes: diskKnown ? capacity!.available_bytes : null,
|
||||
diskTotalBytes: diskKnown ? capacity!.total_bytes : null,
|
||||
archiveUsedBytes: archiveCapacity ? archiveCapacity.current_bytes : null,
|
||||
archiveBudgetBytes: archiveCapacity?.configured ? archiveCapacity.budget_bytes : null,
|
||||
backupUsedBytes: used,
|
||||
backupQuotaBytes: quota !== null && quota > 0 ? quota : null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,13 +269,9 @@ const tonePercent = (value: number, warn: number, critical: number): Tone =>
|
||||
const conclusionText = (tone: Tone): string =>
|
||||
tone === 'ok' ? '正常' : tone === 'warn' ? '注意' : tone === 'bad' ? '需处理' : UNKNOWN_STATE
|
||||
|
||||
export function storageAlerts(
|
||||
inventory: BackupInventory | null,
|
||||
archive: LibraryStorage | null,
|
||||
archiveFailed: boolean
|
||||
): SummaryAlert[] {
|
||||
export function storageAlerts(inventory: BackupInventory | null): SummaryAlert[] {
|
||||
const state = hostState(inventory)
|
||||
const facts = storageFacts(inventory, archive, archiveFailed)
|
||||
const facts = storageFacts(inventory)
|
||||
const diskKnown = facts.diskAvailableBytes !== null && (facts.diskTotalBytes ?? 0) > 0
|
||||
const availablePercent = diskKnown ? Math.round((facts.diskAvailableBytes! / facts.diskTotalBytes!) * 100) : 0
|
||||
const diskTone: Tone = diskKnown
|
||||
@@ -287,16 +282,16 @@ export function storageAlerts(
|
||||
: 'ok'
|
||||
: 'none'
|
||||
|
||||
const quotaKnown = facts.archiveUsedBytes !== null && (facts.archiveBudgetBytes ?? 0) > 0
|
||||
const usedPercent = quotaKnown ? Math.round((facts.archiveUsedBytes! / facts.archiveBudgetBytes!) * 100) : 0
|
||||
const quotaKnown = facts.backupUsedBytes !== null && (facts.backupQuotaBytes ?? 0) > 0
|
||||
const usedPercent = quotaKnown ? Math.round((facts.backupUsedBytes! / facts.backupQuotaBytes!) * 100) : 0
|
||||
const quotaTone: Tone = quotaKnown
|
||||
? tonePercent(usedPercent, QUOTA_WARN_USED_PERCENT, QUOTA_CRITICAL_USED_PERCENT)
|
||||
: 'none'
|
||||
const bothTone: Tone =
|
||||
diskTone === 'none' || quotaTone === 'none' ? 'none' : diskTone !== 'ok' && quotaTone !== 'ok' ? 'bad' : 'ok'
|
||||
const overPhysical: Tone =
|
||||
diskKnown && facts.archiveBudgetBytes !== null
|
||||
? facts.archiveBudgetBytes > facts.diskAvailableBytes!
|
||||
diskKnown && facts.backupQuotaBytes !== null
|
||||
? facts.backupQuotaBytes > facts.diskAvailableBytes!
|
||||
? 'bad'
|
||||
: 'ok'
|
||||
: 'none'
|
||||
@@ -315,12 +310,10 @@ export function storageAlerts(
|
||||
key: 'quota_low',
|
||||
label: '配额不足',
|
||||
value: quotaKnown
|
||||
? `${formatSize(facts.archiveUsedBytes)} / ${formatSize(facts.archiveBudgetBytes)}(${usedPercent}%)`
|
||||
: archiveFailed
|
||||
? UNKNOWN
|
||||
: archive?.available
|
||||
? '配额未设置'
|
||||
: UNKNOWN,
|
||||
? `${formatSize(facts.backupUsedBytes)} / ${formatSize(facts.backupQuotaBytes)}(${usedPercent}%)`
|
||||
: inventory?.quota_error
|
||||
? '配额未上报'
|
||||
: UNKNOWN,
|
||||
tone: quotaTone,
|
||||
conclusion: quotaKnown ? conclusionText(quotaTone) : UNKNOWN_STATE,
|
||||
},
|
||||
@@ -335,11 +328,11 @@ export function storageAlerts(
|
||||
key: 'quota_over_physical',
|
||||
label: '配额超出物理空闲',
|
||||
value:
|
||||
diskKnown && facts.archiveBudgetBytes !== null
|
||||
? `配额 ${formatSize(facts.archiveBudgetBytes)} · 可用 ${formatSize(facts.diskAvailableBytes)}`
|
||||
diskKnown && facts.backupQuotaBytes !== null
|
||||
? `配额 ${formatSize(facts.backupQuotaBytes)} · 可用 ${formatSize(facts.diskAvailableBytes)}`
|
||||
: UNKNOWN,
|
||||
tone: overPhysical,
|
||||
conclusion: diskKnown && facts.archiveBudgetBytes !== null ? conclusionText(overPhysical) : UNKNOWN_STATE,
|
||||
conclusion: diskKnown && facts.backupQuotaBytes !== null ? conclusionText(overPhysical) : UNKNOWN_STATE,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user