Преглед на файлове

Add history of cpu in backend

Florian Hoss преди 2 години
родител
ревизия
d70b3c8ae6
променени са 3 файла, в които са добавени 10 реда и са изтрити 2 реда
  1. 1 0
      system/cpu.go
  2. 2 0
      system/system.go
  3. 7 2
      system/types.go

+ 1 - 0
system/cpu.go

@@ -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)
 }

+ 2 - 0
system/system.go

@@ -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")
 }

+ 7 - 2
system/types.go

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