Skip to content

Commit

Permalink
Merge pull request #1 from ronnocol/meminfoUpdates
Browse files Browse the repository at this point in the history
Update meminfo fields
  • Loading branch information
ronnocol authored Mar 28, 2022
2 parents 78577a7 + 564d3e6 commit 54b39e1
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 32 deletions.
71 changes: 45 additions & 26 deletions mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,51 @@ type VirtualMemoryStat struct {
// https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-meminfo.html
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
// https://www.kernel.org/doc/Documentation/vm/overcommit-accounting
Buffers uint64 `json:"buffers"`
Cached uint64 `json:"cached"`
WriteBack uint64 `json:"writeBack"`
Dirty uint64 `json:"dirty"`
WriteBackTmp uint64 `json:"writeBackTmp"`
Shared uint64 `json:"shared"`
Slab uint64 `json:"slab"`
Sreclaimable uint64 `json:"sreclaimable"`
Sunreclaim uint64 `json:"sunreclaim"`
PageTables uint64 `json:"pageTables"`
SwapCached uint64 `json:"swapCached"`
CommitLimit uint64 `json:"commitLimit"`
CommittedAS uint64 `json:"committedAS"`
HighTotal uint64 `json:"highTotal"`
HighFree uint64 `json:"highFree"`
LowTotal uint64 `json:"lowTotal"`
LowFree uint64 `json:"lowFree"`
SwapTotal uint64 `json:"swapTotal"`
SwapFree uint64 `json:"swapFree"`
Mapped uint64 `json:"mapped"`
VmallocTotal uint64 `json:"vmallocTotal"`
VmallocUsed uint64 `json:"vmallocUsed"`
VmallocChunk uint64 `json:"vmallocChunk"`
HugePagesTotal uint64 `json:"hugePagesTotal"`
HugePagesFree uint64 `json:"hugePagesFree"`
HugePageSize uint64 `json:"hugePageSize"`
Buffers uint64 `json:"buffers"`
Cached uint64 `json:"cached"`
Writeback uint64 `json:"writeBack"`
Dirty uint64 `json:"dirty"`
WriteBackTmp uint64 `json:"writeBackTmp"`
Shared uint64 `json:"shared"`
Slab uint64 `json:"slab"`
Sreclaimable uint64 `json:"sreclaimable"`
Sunreclaim uint64 `json:"sunreclaim"`
PageTables uint64 `json:"pageTables"`
SwapCached uint64 `json:"swapCached"`
CommitLimit uint64 `json:"commitLimit"`
CommittedAS uint64 `json:"committedAS"`
HighTotal uint64 `json:"highTotal"`
HighFree uint64 `json:"highFree"`
LowTotal uint64 `json:"lowTotal"`
LowFree uint64 `json:"lowFree"`
SwapTotal uint64 `json:"swapTotal"`
SwapFree uint64 `json:"swapFree"`
Mapped uint64 `json:"mapped"`
VmallocTotal uint64 `json:"vmallocTotal"`
VmallocUsed uint64 `json:"vmallocUsed"`
VmallocChunk uint64 `json:"vmallocChunk"`
HugePagesTotal uint64 `json:"hugePagesTotal"`
HugePagesFree uint64 `json:"hugePagesFree"`
HugePageSize uint64 `json:"hugePageSize"`
Mlocked uint64 `json:"mlocked"`
AnonPages uint64 `json:"anonPages"`
Kreclaimable uint64 `json:"kreclaimable"`
Nfsunstable uint64 `json:"nfsUnstable"`
Kernelstack uint64 `json:"kernelstack"`
Bounce uint64 `json:"bounce"`
WritebackTmp uint64 `json:"writebackTmp"`
Percpu uint64 `json:"perCpu"`
CmaTotal uint64 `json:"cmaTotal"`
CmaFree uint64 `json:"cmaFree"`
DirectMap4k uint64 `json:"directMap4k"`
DirectMap2M uint64 `json:"directMap2M"`
DirectMap1G uint64 `json:"directMap1G"`
HardwareCorrupted uint64 `json:"hardwareCorrupted"`
AnonHugePages uint64 `json:"anonHugePages"`
ShmemHugePages uint64 `json:"shmemHugePages"`
ShmemPmdMapped uint64 `json:"ShmemPmdMapped"`
HugePagesRsvd uint64 `json:"hugePagesRsvd"`
HugePagesSurp uint64 `json:"hugePagesSurp"`
}

type SwapMemoryStat struct {
Expand Down
128 changes: 124 additions & 4 deletions mem/mem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
ret.Cached = t * 1024
case "SwapCached":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.SwapCached = t * 1024
case "Active":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand Down Expand Up @@ -153,12 +159,12 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
retEx.Unevictable = t * 1024
case "WriteBack":
case "Mlocked":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.WriteBack = t * 1024
ret.Mlocked = t * 1024
case "WriteBackTmp":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand All @@ -171,12 +177,36 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
ret.Dirty = t * 1024
case "Writeback":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Writeback = t * 1024
case "WriteBack":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Writeback = t * 1024
case "AnonPages":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.AnonPages = t * 1024
case "Shmem":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Shared = t * 1024
case "KReclaimable":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Kreclaimable = t * 1024
case "Slab":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand All @@ -196,18 +226,36 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
ret.Sunreclaim = t * 1024
case "KernelStack":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Kernelstack = t * 1024
case "PageTables":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.PageTables = t * 1024
case "SwapCached":
case "NFS_Unstable":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.SwapCached = t * 1024
ret.Nfsunstable = t * 1024
case "Bounce":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Bounce = t * 1024
case "WritebackTmp":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.WritebackTmp = t * 1024
case "CommitLimit":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand Down Expand Up @@ -280,6 +328,12 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
ret.VmallocChunk = t * 1024
case "Percpu":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.Percpu = t * 1024
case "HugePages_Total":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
Expand All @@ -298,6 +352,72 @@ func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, err
return ret, retEx, err
}
ret.HugePageSize = t * 1024
case "CmaTotal":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.CmaTotal = t * 1024
case "CmaFree":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.CmaFree = t * 1024
case "DirectMap4k":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.DirectMap4k = t * 1024
case "DirectMap2M":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.DirectMap2M = t * 1024
case "DirectMap1G":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.DirectMap1G = t * 1024
case "HardwareCorrupted":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.HardwareCorrupted = t * 1024
case "AnonHugePages":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.AnonHugePages = t * 1024
case "ShmemHugePages":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.ShmemHugePages = t * 1024
case "ShmemPmdMapped":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.ShmemPmdMapped = t * 1024
case "HugePages_Rsvd":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.HugePagesRsvd = t * 1024
case "HugePages_Surp":
t, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return ret, retEx, err
}
ret.HugePagesSurp = t * 1024
}
}

Expand Down
4 changes: 2 additions & 2 deletions mem/mem_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var virtualMemoryTests = []struct {
Laundry: 0,
Buffers: 212496384,
Cached: 4069036032,
WriteBack: 0,
Writeback: 0,
Dirty: 176128,
WriteBackTmp: 0,
Shared: 1222402048,
Expand Down Expand Up @@ -78,7 +78,7 @@ var virtualMemoryTests = []struct {
Laundry: 0,
Buffers: 4915200,
Cached: 96829440,
WriteBack: 0,
Writeback: 0,
Dirty: 0,
WriteBackTmp: 0,
Shared: 0,
Expand Down

0 comments on commit 54b39e1

Please sign in to comment.