Place chart points by their time, so a window's samples fill the chart's width

Five minutes at five-second steps is sixty samples on a chart a hundred and
thirty dots wide, and resampling by count drew them on its right half.
Points are now put in the column of their time, held across the columns
between samples, a series that began late starting where it began.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-04 08:55:19 +02:00
1 parent e91f68a3bf
commit 0f70bdc99d
3 files changed
+109 -20

No files matched your search

+25 -17
View File
@@ -201,11 +201,27 @@ func (m consoleModel) series(id string) []chartSeries {
if !m.mon.res.Configured {
src = m.mon.localSeries(id)
}
return toChart(src, m.mon.res.Configured, m.mon.at, monRanges[m.mon.rng].window)
}
// toChart turns what Prometheus gave into chart series placed by time over
// the window that ended when it was read; sampled here, they are spread
// over what was seen.
func toChart(src []promq.Series, timed bool, readAt time.Time, window time.Duration) []chartSeries {
out := make([]chartSeries, 0, len(src))
for _, s := range src {
cs := chartSeries{name: s.Name}
stamped := timed
for _, p := range s.Points {
cs.values = append(cs.values, p.Value)
cs.at = append(cs.at, p.At)
stamped = stamped && !p.At.IsZero()
}
if !stamped {
cs.at = nil
}
if stamped && !readAt.IsZero() {
cs.from, cs.to = readAt.Add(-window), readAt
}
out = append(out, cs)
}
@@ -332,10 +348,10 @@ func (m consoleModel) monitorPanel(pw int) (string, string, string) {
}
netCol := ""
if v, ok := netBy[nd.ID]; ok {
netCol = fmt.Sprintf(" net %s %9s", sparkline(v, 12, 0), bps(last(v)))
netCol = fmt.Sprintf(" net %s %9s", sparkSeries(v, 12, 0), bps(last(v.values)))
}
fmt.Fprintf(&b, " %-16s %s %4.0f%% %s %s %4.0f%% %s%s\n", truncate(nd.ID, 16),
meter(c/100, 8), c, sparkline(cpuBy[nd.ID], sw, 100), meter(mm/100, 8), mm, sparkline(memBy[nd.ID], sw, 100), netCol)
meter(c/100, 8), c, sparkSeries(cpuBy[nd.ID], sw, 100), meter(mm/100, 8), mm, sparkSeries(memBy[nd.ID], sw, 100), netCol)
}
// Each card: busy, memory, heat and power.
if gpus := m.series("gpu"); len(gpus) > 0 {
@@ -343,15 +359,15 @@ func (m consoleModel) monitorPanel(pw int) (string, string, string) {
b.WriteString("\n " + mdBold.Render("GPUs") + "\n")
for _, g := range gpus {
fmt.Fprintf(&b, " %-16s busy %s %4.0f%% memory %s %4.0f%% %3.0f°C %s %4.0f W\n", truncate(g.name, 16),
sparkline(g.values, sw/2, 100), last(g.values), sparkline(vram[g.name], sw/2, 100), last(vram[g.name]),
last(temp[g.name]), sparkline(temp[g.name], 8, 100), last(pow[g.name]))
sparkSeries(g, sw/2, 100), last(g.values), sparkSeries(vram[g.name], sw/2, 100), last(vram[g.name].values),
last(temp[g.name].values), sparkSeries(temp[g.name], 8, 100), last(pow[g.name].values))
}
}
// Each model's requests.
if rps := m.series("rpsby"); len(rps) > 0 {
b.WriteString("\n " + mdBold.Render("Models") + sDim.Render(" requests a second") + "\n")
for _, s := range rps {
fmt.Fprintf(&b, " %-30s %s %s\n", truncate(s.name, 30), sparkline(s.values, max(20, pw-50), 0), rate(last(s.values)))
fmt.Fprintf(&b, " %-30s %s %s\n", truncate(s.name, 30), sparkSeries(s, max(20, pw-50), 0), rate(last(s.values)))
}
}
return "Monitor", head.String() + b.String(), keys
@@ -364,10 +380,10 @@ func named(s []chartSeries, name string) []chartSeries {
return s
}
func byName(s []chartSeries) map[string][]float64 {
out := map[string][]float64{}
func byName(s []chartSeries) map[string]chartSeries {
out := map[string]chartSeries{}
for _, x := range s {
out[x.name] = x.values
out[x.name] = x
}
return out
}
@@ -469,15 +485,7 @@ func (m consoleModel) detailCharts(pw int) string {
return head + " " + sBad.Render(m.det.err.Error())
}
get := func(qid string) []chartSeries {
var out []chartSeries
for _, s := range m.det.res.Series[qid] {
cs := chartSeries{name: s.Name}
for _, p := range s.Points {
cs.values = append(cs.values, p.Value)
}
out = append(out, cs)
}
return out
return toChart(m.det.res.Series[qid], true, m.det.at, r.window)
}
if !m.det.res.Configured {
// Without Prometheus, a node's own samples from this console.