feat(monitors): 接入统一面板数据与按需进程采样
This commit is contained in:
@@ -30,15 +30,32 @@ nonisolated struct MetricsSnapshot: Sendable {
|
||||
var battery: BatteryMetrics?
|
||||
var load: [Double] = []
|
||||
var uptime: TimeInterval = 0
|
||||
// GPU remains unavailable until a reliable IOReport subscription is validated.
|
||||
var gpu: GPUMetrics?
|
||||
var processes: ProcessSnapshot?
|
||||
var diskHealthDate: Date?
|
||||
var batteryHealthDate: Date?
|
||||
var batteryState: BatteryAvailability = .unknown
|
||||
// GPU total is backed by validated IOAccelerator device statistics.
|
||||
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 }
|
||||
let included = network.filter { $0.isIncludedInTotal }
|
||||
guard !included.isEmpty else { return nil }
|
||||
let rates = included.compactMap(\.download)
|
||||
guard rates.count == included.count else { return nil }
|
||||
return rates.reduce(0, +)
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated enum BatteryAvailability: Sendable { case unknown, present, absent, failed }
|
||||
|
||||
nonisolated extension MetricsSnapshot {
|
||||
var uploadRate: Double? {
|
||||
guard let included = network?.filter({ $0.isIncludedInTotal }), !included.isEmpty else { return nil }
|
||||
let values = included.compactMap(\.upload)
|
||||
return values.count == included.count ? values.reduce(0, +) : nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user