41 lines
762 B
Go
41 lines
762 B
Go
package linuxstatus
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func (ls *LinuxStatus) Update() {
|
|
if !ls.Ready() {
|
|
log.Log(WARN, "can't update yet. ready is false")
|
|
log.Error(errors.New("Update() is not ready yet"))
|
|
return
|
|
}
|
|
log.Log(INFO, "Update() START")
|
|
duration := timeFunction(func() {
|
|
linuxLoop()
|
|
})
|
|
ls.setSpeed(duration)
|
|
log.Log(INFO, "Update() END")
|
|
}
|
|
|
|
func (ls *LinuxStatus) setSpeed(duration time.Duration) {
|
|
s := fmt.Sprint(duration)
|
|
if ls.speedActual == nil {
|
|
log.Log(WARN, "can't actually warn")
|
|
return
|
|
}
|
|
ls.speedActual.SetValue(s)
|
|
|
|
if duration > 500*time.Millisecond {
|
|
ls.speed.SetValue("SLOW")
|
|
} else if duration > 100*time.Millisecond {
|
|
ls.speed.SetValue("OK")
|
|
} else {
|
|
ls.speed.SetValue("FAST")
|
|
}
|
|
}
|