mem.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package mem
  2. import (
  3. "encoding/json"
  4. "github.com/shirou/gopsutil/internal/common"
  5. )
  6. var invoke common.Invoker = common.Invoke{}
  7. // Memory usage statistics. Total, Available and Used contain numbers of bytes
  8. // for human consumption.
  9. //
  10. // The other fields in this struct contain kernel specific values.
  11. type VirtualMemoryStat struct {
  12. // Total amount of RAM on this system
  13. Total uint64 `json:"total"`
  14. // RAM available for programs to allocate
  15. //
  16. // This value is computed from the kernel specific values.
  17. Available uint64 `json:"available"`
  18. // RAM used by programs
  19. //
  20. // This value is computed from the kernel specific values.
  21. Used uint64 `json:"used"`
  22. // Percentage of RAM used by programs
  23. //
  24. // This value is computed from the kernel specific values.
  25. UsedPercent float64 `json:"usedPercent"`
  26. // This is the kernel's notion of free memory; RAM chips whose bits nobody
  27. // cares about the value of right now. For a human consumable number,
  28. // Available is what you really want.
  29. Free uint64 `json:"free"`
  30. // OS X / BSD specific numbers:
  31. // http://www.macyourself.com/2010/02/17/what-is-free-wired-active-and-inactive-system-memory-ram/
  32. Active uint64 `json:"active"`
  33. Inactive uint64 `json:"inactive"`
  34. Wired uint64 `json:"wired"`
  35. // FreeBSD specific numbers:
  36. // https://reviews.freebsd.org/D8467
  37. Laundry uint64 `json:"laundry"`
  38. // Linux specific numbers
  39. // https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-meminfo.html
  40. // https://www.kernel.org/doc/Documentation/filesystems/proc.txt
  41. // https://www.kernel.org/doc/Documentation/vm/overcommit-accounting
  42. Buffers uint64 `json:"buffers"`
  43. Cached uint64 `json:"cached"`
  44. Writeback uint64 `json:"writeback"`
  45. Dirty uint64 `json:"dirty"`
  46. WritebackTmp uint64 `json:"writebacktmp"`
  47. Shared uint64 `json:"shared"`
  48. Slab uint64 `json:"slab"`
  49. SReclaimable uint64 `json:"sreclaimable"`
  50. PageTables uint64 `json:"pagetables"`
  51. SwapCached uint64 `json:"swapcached"`
  52. CommitLimit uint64 `json:"commitlimit"`
  53. CommittedAS uint64 `json:"committedas"`
  54. HighTotal uint64 `json:"hightotal"`
  55. HighFree uint64 `json:"highfree"`
  56. LowTotal uint64 `json:"lowtotal"`
  57. LowFree uint64 `json:"lowfree"`
  58. SwapTotal uint64 `json:"swaptotal"`
  59. SwapFree uint64 `json:"swapfree"`
  60. Mapped uint64 `json:"mapped"`
  61. VMallocTotal uint64 `json:"vmalloctotal"`
  62. VMallocUsed uint64 `json:"vmallocused"`
  63. VMallocChunk uint64 `json:"vmallocchunk"`
  64. HugePagesTotal uint64 `json:"hugepagestotal"`
  65. HugePagesFree uint64 `json:"hugepagesfree"`
  66. HugePageSize uint64 `json:"hugepagesize"`
  67. }
  68. type SwapMemoryStat struct {
  69. Total uint64 `json:"total"`
  70. Used uint64 `json:"used"`
  71. Free uint64 `json:"free"`
  72. UsedPercent float64 `json:"usedPercent"`
  73. Sin uint64 `json:"sin"`
  74. Sout uint64 `json:"sout"`
  75. }
  76. func (m VirtualMemoryStat) String() string {
  77. s, _ := json.Marshal(m)
  78. return string(s)
  79. }
  80. func (m SwapMemoryStat) String() string {
  81. s, _ := json.Marshal(m)
  82. return string(s)
  83. }