P8(1): restore homepage overview curves on a memory-only sampling ring
Backend: new overviewMetrics store — a single-tier (2s x 360 = 12min) in-memory ring fed by ServerService.RefreshStatus for exactly the eight overview series (cpu/mem/swap/diskUsage/netUp/netDown/tcpCount/udpCount). No persistence, no gob snapshot, no system-history page: the only surface is GET /panel/api/server/history/:metric/:bucket restricted to those keys, which seeds the frontend curves. ~46KB bounded by construction; the ring starts empty on every panel start. Frontend: restore useOverviewHistory + the VitalTile/ThroughputCard/ ConnectionsCard sparklines and the IndexPage wiring exactly as they were before P7 removed them along with the history module.
This commit is contained in:
@@ -87,8 +87,12 @@ type series struct {
|
||||
}
|
||||
|
||||
func newSeries() *series {
|
||||
s := &series{tiers: make([]*tierBuf, len(metricTiers))}
|
||||
for i, spec := range metricTiers {
|
||||
return newSeriesWithTiers(metricTiers)
|
||||
}
|
||||
|
||||
func newSeriesWithTiers(specs []tierSpec) *series {
|
||||
s := &series{tiers: make([]*tierBuf, len(specs))}
|
||||
for i, spec := range specs {
|
||||
s.tiers[i] = &tierBuf{resolution: spec.resolution, capacity: spec.capacity}
|
||||
}
|
||||
return s
|
||||
@@ -112,14 +116,20 @@ func (s *series) pickTier(spanSeconds int64) *tierBuf {
|
||||
}
|
||||
|
||||
// metricHistory is a thread-safe, in-memory store of tiered series keyed by
|
||||
// arbitrary strings. One singleton lives below: per-node metrics.
|
||||
// arbitrary strings. Two singletons live below: per-node metrics (full
|
||||
// rollup ladder) and the homepage overview series (one small fixed ring).
|
||||
type metricHistory struct {
|
||||
mu sync.Mutex
|
||||
tiers []tierSpec
|
||||
series map[string]*series
|
||||
}
|
||||
|
||||
func newMetricHistory() *metricHistory {
|
||||
return &metricHistory{series: map[string]*series{}}
|
||||
return newMetricHistoryWithTiers(metricTiers)
|
||||
}
|
||||
|
||||
func newMetricHistoryWithTiers(tiers []tierSpec) *metricHistory {
|
||||
return &metricHistory{tiers: tiers, series: map[string]*series{}}
|
||||
}
|
||||
|
||||
// append stores a single sample for the given metric across all tiers.
|
||||
@@ -128,7 +138,7 @@ func (h *metricHistory) append(metric string, t time.Time, v float64) {
|
||||
defer h.mu.Unlock()
|
||||
s := h.series[metric]
|
||||
if s == nil {
|
||||
s = newSeries()
|
||||
s = newSeriesWithTiers(h.tiers)
|
||||
h.series[metric] = s
|
||||
}
|
||||
s.add(t.Unix(), v)
|
||||
@@ -208,12 +218,27 @@ func (h *metricHistory) aggregate(metric string, bucketSeconds int, maxPoints in
|
||||
return out
|
||||
}
|
||||
|
||||
// nodeMetrics is the remaining singleton: per-node CPU/Mem/net series fed by
|
||||
// NodeHeartbeatJob (via UpdateHeartbeat) and read by the node history panel.
|
||||
// The whole-host system series and the xray expvar series that used to live
|
||||
// here were removed with the system-history and xray-metrics features,
|
||||
// together with the gob persistence of the host series.
|
||||
// nodeMetrics holds per-node CPU/Mem/net series fed by NodeHeartbeatJob
|
||||
// (via UpdateHeartbeat) and read by the node history panel. The whole-host
|
||||
// system series and the xray expvar series that used to live here were
|
||||
// removed with the system-history and xray-metrics features, together with
|
||||
// the gob persistence of the host series.
|
||||
var nodeMetrics = newMetricHistory()
|
||||
|
||||
// NodeMetricKeys lists the per-node metric names NodeHeartbeatJob writes.
|
||||
var NodeMetricKeys = []string{"cpu", "mem", "netUp", "netDown"}
|
||||
|
||||
// overviewMetrics is the homepage overview store (P8): a deliberately small,
|
||||
// memory-only ring feeding the index-page sparkline seed — NOT a revival of
|
||||
// the removed system-history feature. One tier at the status cadence (2s)
|
||||
// holding 360 samples = a 12-minute window; eight series of 360 samples are
|
||||
// ~46 KB of payload, bounded by construction. Nothing is persisted: the
|
||||
// ring starts empty on every panel start and the overview curves simply
|
||||
// accumulate from there.
|
||||
var overviewMetrics = newMetricHistoryWithTiers([]tierSpec{{resolution: 2, capacity: 360}})
|
||||
|
||||
// OverviewMetricKeys lists the host metric names ServerService writes on
|
||||
// every status sample for the homepage overview. It matches the frontend
|
||||
// useOverviewHistory SERIES_KEYS exactly; the controller validates incoming
|
||||
// history requests against this allow-list.
|
||||
var OverviewMetricKeys = []string{"cpu", "mem", "swap", "diskUsage", "netUp", "netDown", "tcpCount", "udpCount"}
|
||||
|
||||
Reference in New Issue
Block a user