stats.go 6.1 KB

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