summaryrefslogtreecommitdiffstats
path: root/devices/mem.go
blob: ceff9d6ffce5b5d04d19c3c5c55a0f7712a40efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package devices

import "log"

var memFuncs []func(map[string]MemoryInfo) map[string]error

// TODO Colors are wrong for #mem > 2
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)
			}
		}
	}
}