github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/system/mem/mem.go (about)

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