Add history of cpu in backend

This commit is contained in:
Florian Hoss 2022-10-24 08:05:24 +02:00
parent 48499a9b3f
commit d70b3c8ae6
3 changed files with 11 additions and 3 deletions

View file

@ -26,4 +26,5 @@ func (s *System) liveCpu() {
return
}
s.Live.CPU = math.RoundToEven(p[0])
s.History.CPU = append(s.History.CPU[1:], s.Live.CPU)
}

View file

@ -9,6 +9,7 @@ import (
var Config = SystemConfig{}
var Sys = System{}
var Hist = History{}
func NewSystem() {
config.ParseViperConfig(&Config, config.AddViperConfig("system"))
@ -32,6 +33,7 @@ func (s *System) Initialize() {
s.Static.CPU = staticCpu()
s.Static.Ram = staticRam()
s.Static.Disk = staticDisk()
s.History.CPU = make([]float64, 60)
go s.UpdateLiveInformation()
logrus.WithFields(logrus.Fields{"cpu": s.Static.CPU.Name, "arch": s.Static.CPU.Architecture}).Debug("system updated")
}

View file

@ -38,7 +38,12 @@ type StaticInformation struct {
Disk Disk `json:"disk"`
}
type System struct {
Live LiveInformation `json:"live"`
Static StaticInformation `json:"static"`
type History struct {
CPU []float64 `json:"cpu"`
}
type System struct {
Live LiveInformation `json:"live"`
Static StaticInformation `json:"static"`
History History `json:"history"`
}