...

Source file src/github.com/shirou/gopsutil/mem/mem.go

Documentation: github.com/shirou/gopsutil/mem

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

View as plain text