mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 17:07:47 +02:00
feat(agent): report btrfs filesystems as storage pools (#2315)
Co-authored-by: henrygd <hank@henrygd.me>
This commit is contained in:
@@ -198,6 +198,7 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
|
||||
var fanSums map[string]uint64
|
||||
fanCount := uint64(0)
|
||||
zfsPoolCounts := make(map[string]uint64)
|
||||
zfsCapacityCounts := make(map[string]uint64)
|
||||
|
||||
// Accumulate totals
|
||||
for i := range records {
|
||||
@@ -350,9 +351,19 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
|
||||
}
|
||||
pool := sum.ZfsPools[name]
|
||||
if pool == nil {
|
||||
pool = &system.ZfsPool{}
|
||||
pool = &system.ZfsPool{HideUsage: value.HideUsage, HideIO: value.HideIO}
|
||||
sum.ZfsPools[name] = pool
|
||||
}
|
||||
// Never average physical and usable capacity into the same value.
|
||||
if pool.Raw != value.Raw {
|
||||
pool.Total, pool.Used = 0, 0
|
||||
zfsCapacityCounts[name] = 0
|
||||
}
|
||||
pool.HideUsage = pool.HideUsage && value.HideUsage
|
||||
pool.HideIO = pool.HideIO && value.HideIO
|
||||
pool.DisplayName = value.DisplayName
|
||||
pool.Raw = value.Raw
|
||||
zfsCapacityCounts[name]++
|
||||
pool.Total += value.Total
|
||||
pool.Used += value.Used
|
||||
pool.ReadBytes += value.ReadBytes
|
||||
@@ -476,8 +487,8 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
|
||||
// Average ZFS pool stats.
|
||||
for name, pool := range sum.ZfsPools {
|
||||
entryCount := zfsPoolCounts[name]
|
||||
pool.Total = twoDecimals(pool.Total / float64(entryCount))
|
||||
pool.Used = twoDecimals(pool.Used / float64(entryCount))
|
||||
pool.Total = twoDecimals(pool.Total / float64(zfsCapacityCounts[name]))
|
||||
pool.Used = twoDecimals(pool.Used / float64(zfsCapacityCounts[name]))
|
||||
pool.ReadBytes /= entryCount
|
||||
pool.WriteBytes /= entryCount
|
||||
}
|
||||
|
||||
@@ -889,3 +889,34 @@ func TestAverageContainerStatsSlice_ManyContainers(t *testing.T) {
|
||||
assert.Equal(t, 35.0, result[2].Cpu)
|
||||
assert.Equal(t, 45.0, result[3].Cpu)
|
||||
}
|
||||
|
||||
func TestAverageSystemStatsSlice_ZfsCapacityModes(t *testing.T) {
|
||||
for _, raw := range []bool{false, true} {
|
||||
result := records.AverageSystemStatsSlice([]system.Stats{
|
||||
{ZfsPools: map[string]*system.ZfsPool{"pool": {Total: 200, Used: 40, Raw: !raw, ReadBytes: 100}}},
|
||||
{ZfsPools: map[string]*system.ZfsPool{"pool": {Total: 100, Used: 10, Raw: raw, ReadBytes: 300}}},
|
||||
})
|
||||
assert.Equal(t, &system.ZfsPool{Total: 100, Used: 10, Raw: raw, ReadBytes: 200}, result.ZfsPools["pool"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverageSystemStatsSlice_ZfsDuplicateCharts(t *testing.T) {
|
||||
for _, hide := range []bool{false, true} {
|
||||
result := records.AverageSystemStatsSlice([]system.Stats{
|
||||
{ZfsPools: map[string]*system.ZfsPool{"pool": {HideUsage: true, HideIO: true}}},
|
||||
{ZfsPools: map[string]*system.ZfsPool{"pool": {HideUsage: hide, HideIO: hide}}},
|
||||
})
|
||||
assert.Equal(t, hide, result.ZfsPools["pool"].HideUsage)
|
||||
assert.Equal(t, hide, result.ZfsPools["pool"].HideIO)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverageSystemStatsSlice_BtrfsDisplayName(t *testing.T) {
|
||||
result := records.AverageSystemStatsSlice([]system.Stats{
|
||||
{ZfsPools: map[string]*system.ZfsPool{"b:uuid": {DisplayName: "before", Used: 10}}},
|
||||
{ZfsPools: map[string]*system.ZfsPool{"b:uuid": {DisplayName: "after", Used: 20}}},
|
||||
})
|
||||
require.Len(t, result.ZfsPools, 1)
|
||||
assert.Equal(t, "after", result.ZfsPools["b:uuid"].DisplayName)
|
||||
assert.Equal(t, float64(15), result.ZfsPools["b:uuid"].Used)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user