Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion collector/meminfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"regexp"
"strconv"
"strings"

"github.com/shirou/gopsutil/mem"
)

var (
Expand Down Expand Up @@ -54,7 +56,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
}
fv, err := strconv.ParseFloat(parts[1], 64)
if err != nil {
return nil, fmt.Errorf("invalid value in meminfo: %w", err)
return nil, fmt.Errorf("invalid value in meminfo: %s", err)
}
key := parts[0][:len(parts[0])-1] // remove trailing : from key
// Active(anon) -> Active_anon
Expand All @@ -70,5 +72,12 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
memInfo[key] = fv
}

virtualStats, err := mem.VirtualMemory()
if err != nil {
return nil, fmt.Errorf("failed to get meminfo: %s", err)
}

memInfo["Used_percent"] = virtualStats.UsedPercent

return memInfo, scanner.Err()
}