diff --git a/checkMemory.go b/checkMemory.go new file mode 100644 index 0000000..3d6db10 --- /dev/null +++ b/checkMemory.go @@ -0,0 +1,33 @@ +package main + +import ( + "github.com/c9s/goprocinfo/linux" + "github.com/infrasonar/go-libagent" +) + +func readMemory(state map[string][]map[string]any) error { + mem, err := linux.ReadMemInfo("/proc/meminfo") + if err != nil { + return err + } + + item := map[string]any{ + "name": "memory", + "free": mem.MemFree, + "total": mem.MemTotal, + } + + state["memory"] = []map[string]any{item} + return nil +} + +func CheckMemory(check *libagent.Check) (map[string][]map[string]any, error) { + state := map[string][]map[string]any{} + var err error + + if e := readMemory(state); e != nil { + err = e + } + + return state, err +} diff --git a/main.go b/main.go index 8bfd27e..2cfd61b 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,18 @@ func main() { } go checkDisk.Plan(quit) + CheckMemory := libagent.Check{ + Key: "memory", + Collector: collector, + Asset: asset, + IntervalEnv: "CHECK_MEMORY_INTERVAL", + DefaultInterval: 300, + NoCount: false, + SetTimestamp: false, + Fn: CheckMemory, + } + go CheckMemory.Plan(quit) + // Wait for quit <-quit }