github.com/gofiber/fiber/v2@v2.47.0/internal/gopsutil/mem/mem.go (about)

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