feat(web): switch charts between 1h, 3h, 12h, 24h and 7d with matching SLA

Bars use a resolution fitting the range and the latency line is placed
by time. The SLA is the share of time a monitor was not down, counted
from incidents and only since the monitor exists. Monitor pages list the
SLA from one hour to 90 days.

Closes #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 09:29:34 +01:00
1 parent b210c8e5c0
commit 273a958d76
11 files changed
+1419 -810

No files matched your search

+64 -17
View File
@@ -51,6 +51,33 @@ type DashboardView struct {
Empty bool
CanWrite bool
Counts map[Status]int
Range string
Ranges []RangeOption
}
// RangeOption is an entry of the range switcher.
type RangeOption struct {
Key string
Active bool
URL string
}
// SLAEntry is one window of the SLA table.
type SLAEntry struct {
Label string
Value string
}
templ rangeSwitch(opts []RangeOption) {
<nav class="flex border border-rule font-mono text-xs" aria-label={ i18n.T(ctx, "monitors.range") }>
for _, o := range opts {
if o.Active {
<span class="bg-ink px-2 py-1 text-paper" aria-current="true">{ o.Key }</span>
} else {
<a href={ templ.SafeURL(o.URL) } class="px-2 py-1 text-muted hover:text-ink">{ o.Key }</a>
}
}
</nav>
}
templ statusDot(s Status) {
@@ -96,6 +123,7 @@ templ Dashboard(p Page, me Me, v DashboardView) {
<div class="mb-6 flex items-baseline justify-between gap-4">
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
<div class="flex items-center gap-5 font-mono text-xs text-muted">
@rangeSwitch(v.Ranges)
for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusPaused} {
if v.Counts[s] > 0 {
<span class="flex items-center gap-1.5">
@@ -118,7 +146,7 @@ templ Dashboard(p Page, me Me, v DashboardView) {
@groupBlock(g)
}
</div>
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.last_24h") }</p>
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
}
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
}
@@ -188,6 +216,9 @@ type IncidentRow struct {
// MonitorDetailView is the data of a monitor page.
type MonitorDetailView struct {
Row MonitorRow
Range string
Ranges []RangeOption
SLAs []SLAEntry
Interval string
Daily []Bar
Uptime90 string
@@ -212,6 +243,37 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
<a href={ templ.SafeURL("/monitors/" + v.Row.ID + "/edit") } class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "sso.action.edit") }</a>
}
</div>
<section class="mb-10">
<div class="mb-3 flex items-center justify-between gap-4">
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.history", "Range", v.Range) }</h2>
@rangeSwitch(v.Ranges)
</div>
<div class="mb-1 flex items-baseline justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "monitors.sla") }</span>
<span class="text-sm text-ink">{ v.Row.Uptime }</span>
</div>
@bars(v.Row.Bars, 28)
if v.Latency.Points != "" {
<div class="mt-4 mb-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "monitors.latency") }</span>
<span>max { strconv.Itoa(v.Latency.MaxMS) } ms</span>
</div>
<svg viewBox={ "0 0 " + strconv.Itoa(v.Latency.Width) + " " + strconv.Itoa(v.Latency.Height) } preserveAspectRatio="none" class="block h-24 w-full border-b border-rule">
<polyline points={ v.Latency.Points } fill="none" class="stroke-ink" stroke-width="1.5" vector-effect="non-scaling-stroke"></polyline>
</svg>
}
</section>
<section class="mb-10">
@sectionHeading("monitors.sla_table")
<dl class="grid grid-cols-3 gap-px border border-rule bg-rule sm:grid-cols-7">
for _, e := range v.SLAs {
<div class="bg-paper px-3 py-2">
<dt class="font-mono text-xs text-muted">{ e.Label }</dt>
<dd class="font-mono text-sm">{ e.Value }</dd>
</div>
}
</dl>
</section>
<section class="mb-10">
<div class="mb-2 flex items-baseline justify-between">
@sectionHeading("monitors.last_90d")
@@ -219,7 +281,7 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
</div>
@bars(v.Daily, 28)
</section>
<div class="mb-10 grid gap-10 md:grid-cols-2">
<div class="mb-10">
<section>
@sectionHeading("monitors.regions")
<ul class="divide-y divide-rule border-y border-rule text-sm">
@@ -232,21 +294,6 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
}
</ul>
</section>
<section>
<div class="mb-4 flex items-baseline justify-between">
@sectionHeading("monitors.latency_24h")
if v.Latency.MaxMS > 0 {
<span class="font-mono text-xs text-muted">max { strconv.Itoa(v.Latency.MaxMS) } ms</span>
}
</div>
if v.Latency.Points != "" {
<svg viewBox={ "0 0 " + strconv.Itoa(v.Latency.Width) + " " + strconv.Itoa(v.Latency.Height) } preserveAspectRatio="none" class="block h-24 w-full border-b border-rule">
<polyline points={ v.Latency.Points } fill="none" class="stroke-ink" stroke-width="1.5" vector-effect="non-scaling-stroke"></polyline>
</svg>
} else {
<p class="text-sm text-muted">–</p>
}
</section>
</div>
if len(v.Incidents) > 0 {
<section class="mb-10">