Files
troubleshoot/pkg/collect/host_memory.go
Andrew Reed 10a34c2e58 Host preflight (#311)
* Add HostPreflight v1beta2

* Work on TCP Load Balancer

* Host disk usage collector and analyzer

* Host memory analyzer

* TCP port status

* TCP load balancer

* Review changes

Co-authored-by: Marc Campbell <marc.e.campbell@gmail.com>
2021-02-08 16:09:01 -05:00

32 lines
598 B
Go

package collect
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/shirou/gopsutil/mem"
)
type MemoryInfo struct {
Total uint64 `json:"total"`
}
func HostMemory(c *HostCollector) (map[string][]byte, error) {
memoryInfo := MemoryInfo{}
vmstat, err := mem.VirtualMemory()
if err != nil {
return nil, errors.Wrap(err, "failed to read virtual memory")
}
memoryInfo.Total = vmstat.Available
b, err := json.Marshal(memoryInfo)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal memory info")
}
return map[string][]byte{
"system/memory.json": b,
}, nil
}