mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-16 12:16:36 +00:00
* telemetry: keep the reported version in the daily history The version only ever lived on the instance record, which holds a cluster's latest report, so there was no way to ask what anything ran last Tuesday. Record it per sample, and let the daily axis carry strings as well as counts. State written before this has no version on its samples. The newest sample is the report the instance record itself came from, so fill that one in on load rather than starting a version series a day late. * telemetry: serve the fleet's version make-up over time /api/versions gives how many clusters ran each release per day, on the same axis and hold-forward rule as the cluster sizes. Releases are ordered by number rather than by size: the caller stacks them, and a stack whose order changes with the counts is unreadable over time. The tail past the limit is summed into "other" so the stack still adds up. Days with no version are dropped before the axis is built, so the series spans the days it knows a version for instead of climbing out of blanks. * telemetry: draw version distribution as a stacked growth chart The pie only ever showed today. Stacked over 30 days the height is the confirmed fleet and each band is a release, so one chart carries the growth and the rollouts at once. Newest release on the floor, so the band being read is anchored to the axis instead of riding on everything below it. Eight fixed hues instead of the evenly spaced ones the cluster stacks use: evenly spaced put a green and a cyan close enough to be hard to tell apart, which matters for a set you read rather than a wall of anonymous ids. Versions past the eighth fold into "other", and each band carries its own number so the chart reads without matching colours against the legend.
91 lines
3.0 KiB
Go
91 lines
3.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
// ClusterSeries is one cluster's daily disk usage and volume server count,
|
|
// aligned to the shared date axis of the enclosing ClusterSizeSeries.
|
|
type ClusterSeries struct {
|
|
ClusterId string `json:"cluster_id"`
|
|
Disk []uint64 `json:"disk"`
|
|
Servers []uint64 `json:"servers"`
|
|
}
|
|
|
|
// OtherSeries is the clusters beyond the caller's limit, summed per day so a
|
|
// stacked chart still adds up to the fleet total.
|
|
type OtherSeries struct {
|
|
Count int `json:"count"`
|
|
Disk []uint64 `json:"disk"`
|
|
Servers []uint64 `json:"servers"`
|
|
}
|
|
|
|
// ClusterSizeSeries is per-cluster disk usage and volume server count over
|
|
// time: one value per cluster per day, largest cluster first, ranked by disk on
|
|
// their most recent day. Both metrics share one ranking so a cluster keeps its
|
|
// place, and its colour, across the charts drawn from this.
|
|
type ClusterSizeSeries struct {
|
|
Dates []string `json:"dates"`
|
|
Clusters []ClusterSeries `json:"clusters"`
|
|
Other *OtherSeries `json:"other,omitempty"`
|
|
ClusterCount int `json:"cluster_count"`
|
|
TotalDisk uint64 `json:"total_disk"` // across all clusters on the last day
|
|
TotalServers uint64 `json:"total_servers"` // across all clusters on the last day
|
|
}
|
|
|
|
// GetClusterSizeSeries returns the last `days` days of per-cluster disk usage
|
|
// and volume server counts across confirmed clusters. Clusters beyond `limit`
|
|
// are folded into Other.
|
|
func (s *PrometheusStorage) GetClusterSizeSeries(days, limit int) ClusterSizeSeries {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
|
|
histories := s.seriesHistories()
|
|
axis := newDailySeries(days, histories)
|
|
activeSince := time.Now().UTC().AddDate(0, 0, -activeDays).Unix()
|
|
last := len(axis.dates) - 1
|
|
series := ClusterSizeSeries{Dates: axis.dates}
|
|
|
|
for id, history := range histories {
|
|
disk, ok := align(axis, history, activeSince, diskBytes)
|
|
if !ok {
|
|
continue
|
|
}
|
|
servers, _ := align(axis, history, activeSince, serverCount)
|
|
series.Clusters = append(series.Clusters, ClusterSeries{ClusterId: id, Disk: disk, Servers: servers})
|
|
series.TotalDisk += disk[last]
|
|
series.TotalServers += servers[last]
|
|
}
|
|
series.ClusterCount = len(series.Clusters)
|
|
|
|
// Rank by the latest day so the stack reads largest-first at its right
|
|
// 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[last] != b.Disk[last] {
|
|
return a.Disk[last] > b.Disk[last]
|
|
}
|
|
return a.ClusterId < b.ClusterId
|
|
})
|
|
|
|
if limit > 0 && len(series.Clusters) > limit {
|
|
other := OtherSeries{
|
|
Count: len(series.Clusters) - limit,
|
|
Disk: make([]uint64, len(axis.dates)),
|
|
Servers: make([]uint64, len(axis.dates)),
|
|
}
|
|
for _, c := range series.Clusters[limit:] {
|
|
for i, v := range c.Disk {
|
|
other.Disk[i] += v
|
|
}
|
|
for i, v := range c.Servers {
|
|
other.Servers[i] += v
|
|
}
|
|
}
|
|
series.Clusters = series.Clusters[:limit]
|
|
series.Other = &other
|
|
}
|
|
return series
|
|
}
|