2024-01-06 05:24:11 -06:00
|
|
|
package linuxstatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2024-01-06 11:12:10 -06:00
|
|
|
"errors"
|
2024-01-06 05:24:11 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (ls *LinuxStatus) Update() {
|
2024-01-06 11:12:10 -06:00
|
|
|
if ! ls.Ready() {
|
2024-01-06 13:55:46 -06:00
|
|
|
log.Log(WARN, "can't update yet. ready is false")
|
2024-01-06 11:12:10 -06:00
|
|
|
log.Error(errors.New("Update() is not ready yet"))
|
2024-01-06 05:24:11 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-06 11:12:10 -06:00
|
|
|
log.Log(INFO, "Update() START")
|
2024-01-06 05:24:11 -06:00
|
|
|
duration := timeFunction(func () {
|
|
|
|
linuxLoop()
|
|
|
|
})
|
2024-01-06 11:12:10 -06:00
|
|
|
ls.SetSpeed(duration)
|
2024-01-06 13:55:46 -06:00
|
|
|
log.Log(INFO, "Update() END")
|
2024-01-06 11:12:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ls *LinuxStatus) SetSpeed(duration time.Duration) {
|
2024-01-06 05:24:11 -06:00
|
|
|
s := fmt.Sprint(duration)
|
2024-01-06 11:12:10 -06:00
|
|
|
if ls.speedActual == nil {
|
2024-01-06 13:55:46 -06:00
|
|
|
log.Log(WARN, "can't actually warn")
|
2024-01-06 11:12:10 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-06 05:24:11 -06:00
|
|
|
ls.speedActual.Set(s)
|
|
|
|
|
|
|
|
if (duration > 500 * time.Millisecond ) {
|
2024-01-06 11:12:10 -06:00
|
|
|
ls.speed.Set("SLOW")
|
2024-01-06 05:24:11 -06:00
|
|
|
} else if (duration > 100 * time.Millisecond ) {
|
2024-01-06 11:12:10 -06:00
|
|
|
ls.speed.Set("OK")
|
2024-01-06 05:24:11 -06:00
|
|
|
} else {
|
2024-01-06 11:12:10 -06:00
|
|
|
ls.speed.Set("FAST")
|
2024-01-06 05:24:11 -06:00
|
|
|
}
|
|
|
|
}
|