stats.go 3.7 KB

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