mem.go 3.4 KB

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