mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-05 11:37:44 +01:00
telemetry: fix total disk usage over time (#10476)
* telemetry: total disk usage over time counted each cluster on one day GetMetrics aggregated s.instances, which holds only each cluster's most recent report. Every cluster therefore landed in a single date bucket -- the day it last reported on -- so the chart plotted the disk usage of clusters that went silent that day, and piled the whole live fleet onto today. Aggregate the daily histories instead, reusing the day alignment that the per-cluster size series already does. * telemetry: don't pad the charts with days the server has no history for The dashboard asks for 30 days, but daily history only starts when a server first collects it, so the charts opened on a run of zeros and then jumped -- reading as a fleet that appeared overnight. Start the window at the oldest sample on hand when it is younger than the requested range.
This commit is contained in:
1 parent
ac6f3c92ef
commit
c8cafd8a1a
5 files changed
+245
-72
No files matched your search
@@ -30,52 +30,23 @@ type ClusterSizeSeries struct {
|
||||
}
|
||||
|
||||
// GetClusterSizeSeries returns the last `days` days of per-cluster disk usage.
|
||||
// Clusters beyond `limit` are folded into Other. Clusters report roughly once
|
||||
// a day at no fixed hour, so a day without a report carries the previous value
|
||||
// forward rather than dropping to zero; a cluster that stopped reporting
|
||||
// altogether ends at its last sample instead of holding capacity forever.
|
||||
// Clusters beyond `limit` are folded into Other.
|
||||
func (s *PrometheusStorage) GetClusterSizeSeries(days, limit int) ClusterSizeSeries {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
now := time.Now().UTC()
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
|
||||
dayOf := make(map[string]int, days)
|
||||
series := ClusterSizeSeries{Dates: make([]string, days)}
|
||||
for i := range series.Dates {
|
||||
series.Dates[i] = today.AddDate(0, 0, i-days+1).Format("2006-01-02")
|
||||
dayOf[series.Dates[i]] = i
|
||||
}
|
||||
activeSince := now.AddDate(0, 0, -activeDays).Unix()
|
||||
axis := newDailySeries(days, s.histories)
|
||||
activeSince := time.Now().UTC().AddDate(0, 0, -activeDays).Unix()
|
||||
last := len(axis.dates) - 1
|
||||
series := ClusterSizeSeries{Dates: axis.dates}
|
||||
|
||||
for id, history := range s.histories {
|
||||
disk := make([]uint64, days)
|
||||
reported := make([]bool, days)
|
||||
first, last := -1, -1
|
||||
for _, sample := range history {
|
||||
i, ok := dayOf[time.Unix(sample.Ts, 0).UTC().Format("2006-01-02")]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
disk[i], reported[i] = sample.TotalDiskBytes, true
|
||||
if first < 0 {
|
||||
first = i
|
||||
}
|
||||
last = i
|
||||
if sample.Ts >= activeSince {
|
||||
last = days - 1 // still reporting, so hold its size to the right edge
|
||||
}
|
||||
}
|
||||
if first < 0 {
|
||||
disk, ok := axis.align(history, activeSince, diskBytes)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for i := first + 1; i <= last; i++ {
|
||||
if !reported[i] {
|
||||
disk[i] = disk[i-1]
|
||||
}
|
||||
}
|
||||
series.Clusters = append(series.Clusters, ClusterSeries{ClusterId: id, Disk: disk})
|
||||
series.TotalDisk += disk[days-1]
|
||||
series.TotalDisk += disk[last]
|
||||
}
|
||||
series.ClusterCount = len(series.Clusters)
|
||||
|
||||
@@ -83,8 +54,8 @@ func (s *PrometheusStorage) GetClusterSizeSeries(days, limit int) ClusterSizeSer
|
||||
// edge, tie-breaking on id to keep the order stable across refreshes.
|
||||
sort.Slice(series.Clusters, func(i, j int) bool {
|
||||
a, b := series.Clusters[i], series.Clusters[j]
|
||||
if a.Disk[days-1] != b.Disk[days-1] {
|
||||
return a.Disk[days-1] > b.Disk[days-1]
|
||||
if a.Disk[last] != b.Disk[last] {
|
||||
return a.Disk[last] > b.Disk[last]
|
||||
}
|
||||
return a.ClusterId < b.ClusterId
|
||||
})
|
||||
@@ -92,7 +63,7 @@ func (s *PrometheusStorage) GetClusterSizeSeries(days, limit int) ClusterSizeSer
|
||||
if limit > 0 && len(series.Clusters) > limit {
|
||||
other := OtherSeries{
|
||||
Count: len(series.Clusters) - limit,
|
||||
Disk: make([]uint64, days),
|
||||
Disk: make([]uint64, len(axis.dates)),
|
||||
}
|
||||
for _, c := range series.Clusters[limit:] {
|
||||
for i, v := range c.Disk {
|
||||
|
||||
Reference in new issue
Block a user