github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/cgroups/stats.go (about)

     1  package cgroups
     2  
     3  type ThrottlingData struct {
     4  	// Number of periods with throttling active
     5  	Periods uint64 `json:"periods,omitempty"`
     6  	// Number of periods when the container hit its throttling limit.
     7  	ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
     8  	// Aggregate time the container was throttled for in nanoseconds.
     9  	ThrottledTime uint64 `json:"throttled_time,omitempty"`
    10  }
    11  
    12  // CpuUsage denotes the usage of a CPU.
    13  // All CPU stats are aggregate since container inception.
    14  type CpuUsage struct {
    15  	// Total CPU time consumed.
    16  	// Units: nanoseconds.
    17  	TotalUsage uint64 `json:"total_usage,omitempty"`
    18  	// Total CPU time consumed per core.
    19  	// Units: nanoseconds.
    20  	PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
    21  	// CPU time consumed per core in kernel mode
    22  	// Units: nanoseconds.
    23  	PercpuUsageInKernelmode []uint64 `json:"percpu_usage_in_kernelmode"`
    24  	// CPU time consumed per core in user mode
    25  	// Units: nanoseconds.
    26  	PercpuUsageInUsermode []uint64 `json:"percpu_usage_in_usermode"`
    27  	// Time spent by tasks of the cgroup in kernel mode.
    28  	// Units: nanoseconds.
    29  	UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
    30  	// Time spent by tasks of the cgroup in user mode.
    31  	// Units: nanoseconds.
    32  	UsageInUsermode uint64 `json:"usage_in_usermode"`
    33  }
    34  
    35  type PSIData struct {
    36  	Avg10  float64 `json:"avg10"`
    37  	Avg60  float64 `json:"avg60"`
    38  	Avg300 float64 `json:"avg300"`
    39  	Total  uint64  `json:"total"`
    40  }
    41  
    42  type PSIStats struct {
    43  	Some PSIData `json:"some,omitempty"`
    44  	Full PSIData `json:"full,omitempty"`
    45  }
    46  
    47  type CpuStats struct {
    48  	CpuUsage       CpuUsage       `json:"cpu_usage,omitempty"`
    49  	ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
    50  	PSI            *PSIStats      `json:"psi,omitempty"`
    51  }
    52  
    53  type CPUSetStats struct {
    54  	// List of the physical numbers of the CPUs on which processes
    55  	// in that cpuset are allowed to execute
    56  	CPUs []uint16 `json:"cpus,omitempty"`
    57  	// cpu_exclusive flag
    58  	CPUExclusive uint64 `json:"cpu_exclusive"`
    59  	// List of memory nodes on which processes in that cpuset
    60  	// are allowed to allocate memory
    61  	Mems []uint16 `json:"mems,omitempty"`
    62  	// mem_hardwall flag
    63  	MemHardwall uint64 `json:"mem_hardwall"`
    64  	// mem_exclusive flag
    65  	MemExclusive uint64 `json:"mem_exclusive"`
    66  	// memory_migrate flag
    67  	MemoryMigrate uint64 `json:"memory_migrate"`
    68  	// memory_spread page flag
    69  	MemorySpreadPage uint64 `json:"memory_spread_page"`
    70  	// memory_spread slab flag
    71  	MemorySpreadSlab uint64 `json:"memory_spread_slab"`
    72  	// memory_pressure
    73  	MemoryPressure uint64 `json:"memory_pressure"`
    74  	// sched_load balance flag
    75  	SchedLoadBalance uint64 `json:"sched_load_balance"`
    76  	// sched_relax_domain_level
    77  	SchedRelaxDomainLevel int64 `json:"sched_relax_domain_level"`
    78  }
    79  
    80  type MemoryData struct {
    81  	Usage    uint64 `json:"usage,omitempty"`
    82  	MaxUsage uint64 `json:"max_usage,omitempty"`
    83  	Failcnt  uint64 `json:"failcnt"`
    84  	Limit    uint64 `json:"limit"`
    85  }
    86  
    87  type MemoryStats struct {
    88  	// memory used for cache
    89  	Cache uint64 `json:"cache,omitempty"`
    90  	// usage of memory
    91  	Usage MemoryData `json:"usage,omitempty"`
    92  	// usage of memory + swap
    93  	SwapUsage MemoryData `json:"swap_usage,omitempty"`
    94  	// usage of swap only
    95  	SwapOnlyUsage MemoryData `json:"swap_only_usage,omitempty"`
    96  	// usage of kernel memory
    97  	KernelUsage MemoryData `json:"kernel_usage,omitempty"`
    98  	// usage of kernel TCP memory
    99  	KernelTCPUsage MemoryData `json:"kernel_tcp_usage,omitempty"`
   100  	// usage of memory pages by NUMA node
   101  	// see chapter 5.6 of memory controller documentation
   102  	PageUsageByNUMA PageUsageByNUMA `json:"page_usage_by_numa,omitempty"`
   103  	// if true, memory usage is accounted for throughout a hierarchy of cgroups.
   104  	UseHierarchy bool `json:"use_hierarchy"`
   105  
   106  	Stats map[string]uint64 `json:"stats,omitempty"`
   107  	PSI   *PSIStats         `json:"psi,omitempty"`
   108  }
   109  
   110  type PageUsageByNUMA struct {
   111  	// Embedding is used as types can't be recursive.
   112  	PageUsageByNUMAInner
   113  	Hierarchical PageUsageByNUMAInner `json:"hierarchical,omitempty"`
   114  }
   115  
   116  type PageUsageByNUMAInner struct {
   117  	Total       PageStats `json:"total,omitempty"`
   118  	File        PageStats `json:"file,omitempty"`
   119  	Anon        PageStats `json:"anon,omitempty"`
   120  	Unevictable PageStats `json:"unevictable,omitempty"`
   121  }
   122  
   123  type PageStats struct {
   124  	Total uint64           `json:"total,omitempty"`
   125  	Nodes map[uint8]uint64 `json:"nodes,omitempty"`
   126  }
   127  
   128  type PidsStats struct {
   129  	// number of pids in the cgroup
   130  	Current uint64 `json:"current,omitempty"`
   131  	// active pids hard limit
   132  	Limit uint64 `json:"limit,omitempty"`
   133  }
   134  
   135  type BlkioStatEntry struct {
   136  	Major uint64 `json:"major,omitempty"`
   137  	Minor uint64 `json:"minor,omitempty"`
   138  	Op    string `json:"op,omitempty"`
   139  	Value uint64 `json:"value,omitempty"`
   140  }
   141  
   142  type BlkioStats struct {
   143  	// number of bytes transferred to and from the block device
   144  	IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"`
   145  	IoServicedRecursive     []BlkioStatEntry `json:"io_serviced_recursive,omitempty"`
   146  	IoQueuedRecursive       []BlkioStatEntry `json:"io_queue_recursive,omitempty"`
   147  	IoServiceTimeRecursive  []BlkioStatEntry `json:"io_service_time_recursive,omitempty"`
   148  	IoWaitTimeRecursive     []BlkioStatEntry `json:"io_wait_time_recursive,omitempty"`
   149  	IoMergedRecursive       []BlkioStatEntry `json:"io_merged_recursive,omitempty"`
   150  	IoTimeRecursive         []BlkioStatEntry `json:"io_time_recursive,omitempty"`
   151  	SectorsRecursive        []BlkioStatEntry `json:"sectors_recursive,omitempty"`
   152  	PSI                     *PSIStats        `json:"psi,omitempty"`
   153  }
   154  
   155  type HugetlbStats struct {
   156  	// current res_counter usage for hugetlb
   157  	Usage uint64 `json:"usage,omitempty"`
   158  	// maximum usage ever recorded.
   159  	MaxUsage uint64 `json:"max_usage,omitempty"`
   160  	// number of times hugetlb usage allocation failure.
   161  	Failcnt uint64 `json:"failcnt"`
   162  }
   163  
   164  type RdmaEntry struct {
   165  	Device     string `json:"device,omitempty"`
   166  	HcaHandles uint32 `json:"hca_handles,omitempty"`
   167  	HcaObjects uint32 `json:"hca_objects,omitempty"`
   168  }
   169  
   170  type RdmaStats struct {
   171  	RdmaLimit   []RdmaEntry `json:"rdma_limit,omitempty"`
   172  	RdmaCurrent []RdmaEntry `json:"rdma_current,omitempty"`
   173  }
   174  
   175  type MiscStats struct {
   176  	// current resource usage for a key in misc
   177  	Usage uint64 `json:"usage,omitempty"`
   178  	// number of times the resource usage was about to go over the max boundary
   179  	Events uint64 `json:"events,omitempty"`
   180  }
   181  
   182  type Stats struct {
   183  	CpuStats    CpuStats    `json:"cpu_stats,omitempty"`
   184  	CPUSetStats CPUSetStats `json:"cpuset_stats,omitempty"`
   185  	MemoryStats MemoryStats `json:"memory_stats,omitempty"`
   186  	PidsStats   PidsStats   `json:"pids_stats,omitempty"`
   187  	BlkioStats  BlkioStats  `json:"blkio_stats,omitempty"`
   188  	// the map is in the format "size of hugepage: stats of the hugepage"
   189  	HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"`
   190  	RdmaStats    RdmaStats               `json:"rdma_stats,omitempty"`
   191  	// the map is in the format "misc resource name: stats of the key"
   192  	MiscStats map[string]MiscStats `json:"misc_stats,omitempty"`
   193  }
   194  
   195  func NewStats() *Stats {
   196  	memoryStats := MemoryStats{Stats: make(map[string]uint64)}
   197  	hugetlbStats := make(map[string]HugetlbStats)
   198  	miscStats := make(map[string]MiscStats)
   199  	return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats, MiscStats: miscStats}
   200  }