feat(diagnostics): 验证统一面板沙盒指标读取能力
This commit is contained in:
@@ -4,6 +4,7 @@ import Darwin
|
||||
/// Serial ownership keeps CPU baselines coherent and system calls off MainActor.
|
||||
actor SystemSampler {
|
||||
private var cpu = CPUMonitor()
|
||||
private var didProbe = false
|
||||
private let diskHealth = DiskHealthMonitor()
|
||||
private let batteryHealth = SystemBatteryHealthMonitor()
|
||||
|
||||
@@ -16,6 +17,13 @@ actor SystemSampler {
|
||||
func reset() { cpu = CPUMonitor(); network = NetworkMonitor(); diskIO = DiskIOMonitor() }
|
||||
|
||||
func sample() async -> MetricsSnapshot {
|
||||
if !didProbe {
|
||||
didProbe = true
|
||||
if ProcessInfo.processInfo.environment["KYMO_PANEL_PROBE"] == "1" {
|
||||
PanelCapabilityProbe.run()
|
||||
}
|
||||
}
|
||||
let sampleStart = ProcessInfo.processInfo.systemUptime
|
||||
var result = MetricsSnapshot()
|
||||
result.cpu = cpu.sample()
|
||||
result.memory = MemoryMonitor.sample()
|
||||
@@ -35,6 +43,10 @@ actor SystemSampler {
|
||||
result.uptime = ProcessInfo.processInfo.systemUptime
|
||||
var load = [Double](repeating: 0, count: 3)
|
||||
if getloadavg(&load, 3) == 3 { result.load = load }
|
||||
if ProcessInfo.processInfo.environment["KYMO_PANEL_PROBE"] == "1" {
|
||||
let line = "{\"event\":\"sampleDuration\",\"milliseconds\":\((ProcessInfo.processInfo.systemUptime - sampleStart) * 1000)}\n"
|
||||
try? FileHandle.standardOutput.write(contentsOf: Data(line.utf8))
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user