package web import ( "context" "fmt" "time" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) // StorageView summarizes how check data is stored and cleaned up. type StorageView struct { Levels []StorageLevel Jobs []StorageJob Tables []StorageTable } // StorageLevel is raw results or one of the aggregates. type StorageLevel struct { Key string Size string Compressed string Chunks string Retention string CompressAfter string } // StorageJob is a TimescaleDB background job. type StorageJob struct { Name string Relation string OK bool LastRun string NextRun string Failures int64 } // StorageTable is a regular table and its size. type StorageTable struct { Name string Size string } // Bytes formats n in binary units. func Bytes(n int64) string { const unit = 1024 if n < unit { return fmt.Sprintf("%d B", n) } div, exp := int64(unit), 0 for m := n / unit; m >= unit; m /= unit { div *= unit exp++ } return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp]) } // Days formats a retention period; zero means forever. func Days(ctx context.Context, d time.Duration) string { if d == 0 { return i18n.T(ctx, "storage.forever") } if d%(24*time.Hour) == 0 { return i18n.T(ctx, "storage.days", "Count", int(d/(24*time.Hour))) } return d.String() } templ storageSection(v StorageView) {
@sectionHeading("storage.title")

{ i18n.T(ctx, "storage.intro") }

for _, l := range v.Levels { }
{ i18n.T(ctx, "storage.level") } { i18n.T(ctx, "storage.size") } { i18n.T(ctx, "storage.chunks") } { i18n.T(ctx, "storage.compress_after") } { i18n.T(ctx, "storage.retention") }
{ i18n.T(ctx, "storage.level_" + l.Key) } { l.Size } if l.Compressed != "" { { " · " + l.Compressed } } { l.Chunks } { l.CompressAfter } { l.Retention }
if len(v.Tables) > 0 {

for i, t := range v.Tables { if i > 0 { { " · " } } { t.Name + " " + t.Size } }

}

{ i18n.T(ctx, "storage.jobs") }

}