This commit is contained in:
Mark Gregory
2026-10-21 14:54:07 +01:00
parent 8c7b29d50f
commit 578f0218a5
6 changed files with 79 additions and 8 deletions
+17 -1
View File
@@ -35,7 +35,12 @@ struct MonitorMenuView: View {
Spacer()
if monitor.results[server.id]?.refreshing == true { ProgressView().controlSize(.mini) }
else if let report = monitor.results[server.id]?.report {
Text("\(report.counts.ok) OK").font(.caption2).foregroundStyle(.secondary)
VStack(alignment: .trailing, spacing: 2) {
Text("\(report.counts.ok) OK").font(.caption2)
if let uptime = report.uptimeLabel {
Text("Up \(uptime)").font(.caption2)
}
}.foregroundStyle(.secondary)
}
if server.id == monitor.selectedID { Image(systemName: "checkmark") }
}.padding(.horizontal, 14).padding(.vertical, 8)
@@ -55,6 +60,17 @@ struct MonitorMenuView: View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
if let report = monitor.report {
HStack(spacing: 8) {
Image(systemName: "clock.arrow.circlepath")
.foregroundStyle(.secondary)
Text("Uptime").font(.system(size: 12, weight: .medium))
Spacer()
Text(report.uptimeLabel ?? "Not available")
.font(.system(size: 12, weight: .medium, design: .monospaced))
.foregroundStyle(.secondary)
}
.padding(.horizontal, 14).padding(.vertical, 10)
Divider()
if !monitor.selectedServices.isEmpty {
Text("SERVICES")
.font(.caption.bold()).foregroundStyle(.secondary)
+11 -1
View File
@@ -15,6 +15,16 @@ struct HealthReport: Codable {
let schema: Int
let host: String?
let generatedAt: String?
let uptimeSeconds: Int?
var uptimeLabel: String? {
guard let uptimeSeconds, uptimeSeconds >= 0 else { return nil }
let days = uptimeSeconds / 86400
let hours = (uptimeSeconds % 86400) / 3600
let minutes = (uptimeSeconds % 3600) / 60
if days > 0 { return "\(days)d \(hours)h \(minutes)m" }
if hours > 0 { return "\(hours)h \(minutes)m" }
return "\(minutes)m"
}
let overall: HealthStatus
let counts: HealthCounts
let groups: [HealthGroup]
@@ -190,7 +200,7 @@ final class ServerMonitor: ObservableObject {
let checks = report.checks + extra
let counts = HealthCounts(ok: report.counts.ok, warn: report.counts.warn, fail: report.counts.fail + extra.count)
let groups = report.groups + [HealthGroup(name: "Required services", status: .fail, missing: extra.map(\.name))]
return HealthReport(schema: report.schema, host: report.host, generatedAt: report.generatedAt, overall: .fail,
return HealthReport(schema: report.schema, host: report.host, generatedAt: report.generatedAt, uptimeSeconds: report.uptimeSeconds, overall: .fail,
counts: counts, groups: groups, checks: checks, diagnostics: report.diagnostics, services: report.services)
}
var status: HealthStatus {