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

+13 -5
View File
@@ -98,20 +98,28 @@ type LatencyLine struct {
Height int
}
// Latency plots the average latency of buckets, oldest first.
func Latency(buckets []Bucket, width, height int) LatencyLine {
// Latency plots the average latency of buckets, oldest first, placing each
// point at its time within [from, to] so the line lines up with the bars.
// Buckets without results are skipped.
func Latency(buckets []Bucket, from, to time.Time, width, height int) LatencyLine {
l := LatencyLine{Width: width, Height: height}
var max float32
var points []Bucket
for _, b := range buckets {
if b.Total == 0 || b.Start.Before(from) {
continue
}
points = append(points, b)
max = maxf(max, b.Latency)
}
if len(buckets) < 2 || max == 0 {
span := to.Sub(from)
if len(points) < 2 || max == 0 || span <= 0 {
return l
}
l.MaxMS = int(max)
var sb strings.Builder
for i, b := range buckets {
x := float64(i) * float64(width) / float64(len(buckets)-1)
for _, b := range points {
x := float64(b.Start.Sub(from)) / float64(span) * float64(width)
y := float64(height) - float64(b.Latency/max)*float64(height-2) - 1
fmt.Fprintf(&sb, "%.1f,%.1f ", x, y)
}