Skip to content

Commit

Permalink
Merge pull request #1 from infrasonar/dev
Browse files Browse the repository at this point in the history
add memory check
  • Loading branch information
joente authored Oct 18, 2024
2 parents 2a3cc2c + 9bd216c commit a3bb84e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions checkMemory.go
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a3bb84e

Please sign in to comment.