xmtop/devices/mem.go
Sean E. Russell 7a89225d72 Abstracts CPU & mem devices.
Finishes device refactoring: temps

Refactoring to allow updating maps. Simpler, and optimizable.
2020-02-28 07:06:51 -06:00

27 lines
466 B
Go

package devices
import "log"
var memFuncs []func(map[string]MemoryInfo) map[string]error
type MemoryInfo struct {
Total uint64
Used uint64
UsedPercent float64
}
func RegisterMem(f func(map[string]MemoryInfo) map[string]error) {
memFuncs = append(memFuncs, f)
}
func UpdateMem(mem map[string]MemoryInfo) {
for _, f := range memFuncs {
errs := f(mem)
if errs != nil {
for k, e := range errs {
log.Printf("%s: %s", k, e)
}
}
}
}