12345678910111213141516171819202122232425262728293031323334353637 |
- package gupta
- import (
- "bytes"
- "io"
- "strconv"
- "strings"
- )
- type Memory struct {
- total uint64
- free uint64
- }
- func (m *Memory) Free() uint64 {
- return m.free
- }
- func (m *Memory) Total() uint64 {
- return m.total
- }
- func (m *Memory) Used() uint64 {
- return m.total - m.free
- }
- func NewMemory(r io.ReaderAt) Memory {
- m := Memory{}
- buf := make([]byte, 80)
- r.ReadAt(buf, 0)
- idx := bytes.Index(buf, []byte("MemAvailable"))
- line := string(buf[:idx])
- elements := strings.Fields(line)
- m.total, _ = strconv.ParseUint(elements[1], 10, 64)
- m.free, _ = strconv.ParseUint(elements[4], 10, 64)
- return m
- }
|