github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/cgroups/stats.go (about) 1 // +build linux 2 3 package cgroups 4 5 type ThrottlingData struct { 6 // Number of periods with throttling active 7 Periods uint64 `json:"periods,omitempty"` 8 // Number of periods when the container hit its throttling limit. 9 ThrottledPeriods uint64 `json:"throttled_periods,omitempty"` 10 // Aggregate time the container was throttled for in nanoseconds. 11 ThrottledTime uint64 `json:"throttled_time,omitempty"` 12 } 13 14 // CpuUsage denotes the usage of a CPU. 15 // All CPU stats are aggregate since container inception. 16 type CpuUsage struct { 17 // Total CPU time consumed. 18 // Units: nanoseconds. 19 TotalUsage uint64 `json:"total_usage,omitempty"` 20 // Total CPU time consumed per core. 21 // Units: nanoseconds. 22 PercpuUsage []uint64 `json:"percpu_usage,omitempty"` 23 // Time spent by tasks of the cgroup in kernel mode. 24 // Units: nanoseconds. 25 UsageInKernelmode uint64 `json:"usage_in_kernelmode"` 26 // Time spent by tasks of the cgroup in user mode. 27 // Units: nanoseconds. 28 UsageInUsermode uint64 `json:"usage_in_usermode"` 29 } 30 31 type CpuStats struct { 32 CpuUsage CpuUsage `json:"cpu_usage,omitempty"` 33 ThrottlingData ThrottlingData `json:"throttling_data,omitempty"` 34 } 35 36 type MemoryData struct { 37 Usage uint64 `json:"usage,omitempty"` 38 MaxUsage uint64 `json:"max_usage,omitempty"` 39 Failcnt uint64 `json:"failcnt"` 40 Limit uint64 `json:"limit"` 41 } 42 43 type MemoryStats struct { 44 // memory used for cache 45 Cache uint64 `json:"cache,omitempty"` 46 // usage of memory 47 Usage MemoryData `json:"usage,omitempty"` 48 // usage of memory + swap 49 SwapUsage MemoryData `json:"swap_usage,omitempty"` 50 // usage of kernel memory 51 KernelUsage MemoryData `json:"kernel_usage,omitempty"` 52 // usage of kernel TCP memory 53 KernelTCPUsage MemoryData `json:"kernel_tcp_usage,omitempty"` 54 55 Stats map[string]uint64 `json:"stats,omitempty"` 56 } 57 58 type PidsStats struct { 59 // number of pids in the cgroup 60 Current uint64 `json:"current,omitempty"` 61 // active pids hard limit 62 Limit uint64 `json:"limit,omitempty"` 63 } 64 65 type BlkioStatEntry struct { 66 Major uint64 `json:"major,omitempty"` 67 Minor uint64 `json:"minor,omitempty"` 68 Op string `json:"op,omitempty"` 69 Value uint64 `json:"value,omitempty"` 70 } 71 72 type BlkioStats struct { 73 // number of bytes tranferred to and from the block device 74 IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"` 75 IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive,omitempty"` 76 IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive,omitempty"` 77 IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive,omitempty"` 78 IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive,omitempty"` 79 IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive,omitempty"` 80 IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive,omitempty"` 81 SectorsRecursive []BlkioStatEntry `json:"sectors_recursive,omitempty"` 82 } 83 84 type HugetlbStats struct { 85 // current res_counter usage for hugetlb 86 Usage uint64 `json:"usage,omitempty"` 87 // maximum usage ever recorded. 88 MaxUsage uint64 `json:"max_usage,omitempty"` 89 // number of times hugetlb usage allocation failure. 90 Failcnt uint64 `json:"failcnt"` 91 } 92 93 type Stats struct { 94 CpuStats CpuStats `json:"cpu_stats,omitempty"` 95 MemoryStats MemoryStats `json:"memory_stats,omitempty"` 96 PidsStats PidsStats `json:"pids_stats,omitempty"` 97 BlkioStats BlkioStats `json:"blkio_stats,omitempty"` 98 // the map is in the format "size of hugepage: stats of the hugepage" 99 HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"` 100 } 101 102 func NewStats() *Stats { 103 memoryStats := MemoryStats{Stats: make(map[string]uint64)} 104 hugetlbStats := make(map[string]HugetlbStats) 105 return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats} 106 }