feat(monitors): 实现 C 阶段网络存储电池监控与三语详情

This commit is contained in:
2026-10-30 16:02:46 +08:00
parent 1cb67b86e8
commit 069e2e100f
22 changed files with 1237 additions and 13 deletions
+6 -1
View File
@@ -5,6 +5,9 @@ nonisolated struct TrendSample: Sendable {
let cpu: Double?
let gpu: Double?
let memory: Double?
var download: Double?
var disk: Double?
var battery: Double?
}
/// Bounded sampling history; no timer or UI visibility dependence.
@@ -14,7 +17,9 @@ nonisolated struct MetricHistory: Sendable {
mutating func append(_ snapshot: MetricsSnapshot) {
samples.append(TrendSample(date: snapshot.date, cpu: snapshot.cpu?.usage,
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage))
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage,
download: snapshot.downloadRate, disk: snapshot.disk?.usage,
battery: snapshot.battery?.charge))
if samples.count > Self.capacity { samples.removeFirst(samples.count - Self.capacity) }
}
}
+15
View File
@@ -21,8 +21,23 @@ nonisolated struct MetricsSnapshot: Sendable {
var date = Date()
var cpu: CPUMetrics?
var memory: MemoryMetrics?
var network: [NetworkInterfaceMetrics]?
var networkPath: NetworkPathStatus?
var disk: DiskMetrics?
var diskIO: DiskIOMetrics?
var volumes: [VolumeMetrics]?
var battery: BatteryMetrics?
var load: [Double] = []
var uptime: TimeInterval = 0
// GPU remains unavailable until a reliable IOReport subscription is validated.
var gpuUsage: Double? = nil
}
nonisolated extension MetricsSnapshot {
var downloadRate: Double? {
guard let network else { return nil }
let rates = network.compactMap(\.download)
guard rates.count == network.count else { return nil }
return rates.reduce(0, +)
}
}