Add per-resource history and guest network groups
This commit is contained in:
32
history.go
32
history.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
@@ -15,6 +16,7 @@ func runHistoryCollector(collect func() (dashboardMetrics, error), store *Store)
|
||||
if err := store.AddHistory(historyPointFromMetrics(metrics)); err != nil {
|
||||
log.Printf("Не удалось сохранить исторические метрики: %v", err)
|
||||
}
|
||||
store.AddEntityMetrics(metrics)
|
||||
}
|
||||
record()
|
||||
ticker := time.NewTicker(time.Minute)
|
||||
@@ -24,6 +26,36 @@ func runHistoryCollector(collect func() (dashboardMetrics, error), store *Store)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) AddEntityMetrics(metrics dashboardMetrics) {
|
||||
ts := time.Now().Unix()
|
||||
for _, p := range metrics.ZFS.Pools {
|
||||
v := p.CapacityPercent
|
||||
s.AddEntityHistory("zfs", p.Name, ts, &v, nil)
|
||||
}
|
||||
for _, g := range metrics.Guests.Guests {
|
||||
if g.Template != 0 {
|
||||
continue
|
||||
}
|
||||
cpu := g.CPU * 100
|
||||
var mem float64
|
||||
if g.MaxMemory > 0 {
|
||||
mem = float64(g.MemoryBytes) / float64(g.MaxMemory) * 100
|
||||
}
|
||||
s.AddEntityHistory("guest", fmt.Sprintf("%d · %s", g.VMID, g.Name), ts, &cpu, &mem)
|
||||
}
|
||||
for _, d := range metrics.Disks {
|
||||
if d.Temperature == nil {
|
||||
continue
|
||||
}
|
||||
var wear *float64
|
||||
if d.WearUsedPercent != nil {
|
||||
wear = d.WearUsedPercent
|
||||
}
|
||||
s.AddEntityHistory("disk", d.Name+" · "+d.Model, ts, d.Temperature, wear)
|
||||
}
|
||||
s.PruneEntityHistory()
|
||||
}
|
||||
|
||||
func historyPointFromMetrics(metrics dashboardMetrics) HistoryPoint {
|
||||
point := HistoryPoint{
|
||||
Timestamp: time.Now().Unix(), CPUUsage: metrics.CPU.UsagePercent,
|
||||
|
||||
Reference in New Issue
Block a user