mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-29 14:04:46 +03:00
05e8f17268
Every overview chart gets the same range selector: 2m, 5m, 30m, 1h, 6h and 12h. The 2m default is the live trend the page already drew, one point per status poll, so nothing changes until a longer range is picked. A longer range is read from the server's stored rollups through the new GET /panel/api/server/overviewHistory/:bucket, which returns all eight overview series in one response, and is refreshed once per point, at most once a minute. A metric the host cannot report stays empty in a ranged window instead of drawing zeros, a range change clears the chart rather than showing the old range under the new label, and avg/peak labels keep their number order in RTL locales.
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The overview draws eight charts from this one response; a series missing from it
|
|
// or filled from another metric's samples leaves a chart blank or wrong.
|
|
func TestAggregateOverviewHistoryCarriesEveryOverviewSeries(t *testing.T) {
|
|
old := systemMetrics
|
|
systemMetrics = newMetricHistory()
|
|
t.Cleanup(func() { systemMetrics = old })
|
|
want := map[string]float64{
|
|
"cpu": 11, "mem": 22, "swap": 33, "diskUsage": 44,
|
|
"netUp": 55, "netDown": 66, "tcpCount": 77, "udpCount": 88,
|
|
}
|
|
now := time.Now()
|
|
for key, value := range want {
|
|
systemMetrics.append(key, now, value)
|
|
}
|
|
systemMetrics.append("load1", now, 99)
|
|
|
|
got := (&ServerService{lastStatus: &Status{}}).AggregateOverviewHistory(2, 60)
|
|
if len(got) != len(want) {
|
|
t.Fatalf("series = %d, want the %d the overview draws: %v", len(got), len(want), got)
|
|
}
|
|
for key, value := range want {
|
|
if points := got[key]; len(points) != 1 || points[0]["v"] != value {
|
|
t.Errorf("%s = %v, want one point of %v", key, points, value)
|
|
}
|
|
}
|
|
}
|