package views import "fmt" import "time" // FormatBytes converts bytes to human-readable format func FormatBytes(bytes uint64) string { const ( kb = 1024 mb = kb * 1024 gb = mb * 1024 tb = gb * 1024 ) switch { case bytes >= tb: return fmt.Sprintf("%.2f TB", float64(bytes)/float64(tb)) case bytes >= gb: return fmt.Sprintf("%.2f GB", float64(bytes)/float64(gb)) case bytes >= mb: return fmt.Sprintf("%.2f MB", float64(bytes)/float64(mb)) case bytes >= kb: return fmt.Sprintf("%.2f KB", float64(bytes)/float64(kb)) default: return fmt.Sprintf("%d B", bytes) } } // FormatPercent formats percentage with 1 decimal place func FormatPercent(percent float64) string { return fmt.Sprintf("%.1f%%", percent) } // FormatTime formats time as relative or absolute func FormatTime(t time.Time) string { if t.IsZero() { return "Never" } duration := time.Since(t) switch { case duration < time.Minute: return "Just now" case duration < time.Hour: return fmt.Sprintf("%d minutes ago", int(duration.Minutes())) case duration < 24*time.Hour: return fmt.Sprintf("%d hours ago", int(duration.Hours())) case duration < 30*24*time.Hour: return fmt.Sprintf("%d days ago", int(duration.Hours()/24)) default: return fmt.Sprintf("%d months ago", int(duration.Hours()/24/30)) } } // StatusColor returns CSS class for status based on conditions func StatusColor(cpuUsage, ramPercent, lastSeenAge time.Duration) string { if lastSeenAge > 24*time.Hour { return "status-red" } if cpuUsage > 80 || ramPercent > 80 { return "status-yellow" } return "status-green" } // IsAgentOnline checks if agent is currently online (reported within 15 seconds) func IsAgentOnline(lastSeen time.Time) bool { return time.Since(lastSeen) < 15*time.Second } templ StatusCard(label string, value string, status string) {
These agents may be offline. You can remove them to keep your dashboard clean.