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