mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 19:03:54 +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
@@ -1,7 +1,6 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -165,41 +164,35 @@ func (s *PrometheusStorage) GetInstances(limit int) ([]*telemetryData, error) {
|
||||
return instances, nil
|
||||
}
|
||||
|
||||
// GetMetrics returns fleet-wide daily totals for the last `days` days, in the
|
||||
// parallel-array shape the dashboard charts expect. Totals come from the daily
|
||||
// histories rather than from s.instances, which holds only each cluster's most
|
||||
// recent report and so would credit every cluster to the single day it last
|
||||
// reported on.
|
||||
func (s *PrometheusStorage) GetMetrics(days int) (map[string]interface{}, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
// Return current metrics from in-memory storage, aggregated per day
|
||||
// in the parallel-array shape the dashboard charts expect.
|
||||
// Historical data should be queried from Prometheus directly.
|
||||
cutoff := time.Now().AddDate(0, 0, -days)
|
||||
axis := newDailySeries(days, s.histories)
|
||||
activeSince := time.Now().UTC().AddDate(0, 0, -activeDays).Unix()
|
||||
|
||||
serverCountByDate := make(map[string]int64)
|
||||
diskUsageByDate := make(map[string]uint64)
|
||||
|
||||
for _, instance := range s.instances {
|
||||
if instance.ReceivedAt.After(cutoff) {
|
||||
date := instance.ReceivedAt.Format("2006-01-02")
|
||||
serverCountByDate[date] += int64(instance.TelemetryData.VolumeServerCount)
|
||||
diskUsageByDate[date] += instance.TelemetryData.TotalDiskBytes
|
||||
diskUsage := make([]uint64, len(axis.dates))
|
||||
serverCounts := make([]int64, len(axis.dates))
|
||||
for _, history := range s.histories {
|
||||
if disk, ok := axis.align(history, activeSince, diskBytes); ok {
|
||||
for i, v := range disk {
|
||||
diskUsage[i] += v
|
||||
}
|
||||
}
|
||||
if servers, ok := axis.align(history, activeSince, serverCount); ok {
|
||||
for i, v := range servers {
|
||||
serverCounts[i] += int64(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dates := make([]string, 0, len(serverCountByDate))
|
||||
for date := range serverCountByDate {
|
||||
dates = append(dates, date)
|
||||
}
|
||||
sort.Strings(dates)
|
||||
|
||||
serverCounts := make([]int64, 0, len(dates))
|
||||
diskUsage := make([]uint64, 0, len(dates))
|
||||
for _, date := range dates {
|
||||
serverCounts = append(serverCounts, serverCountByDate[date])
|
||||
diskUsage = append(diskUsage, diskUsageByDate[date])
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"dates": dates,
|
||||
"dates": axis.dates,
|
||||
"server_counts": serverCounts,
|
||||
"disk_usage": diskUsage,
|
||||
}, nil
|
||||
|
||||
Reference in new issue
Block a user