stats.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Package types is used for API stability in the types and response to the
  2. // consumers of the API stats endpoint.
  3. package types
  4. import "time"
  5. // ThrottlingData stores CPU throttling stats of one running container
  6. type ThrottlingData struct {
  7. // Number of periods with throttling active
  8. Periods uint64 `json:"periods"`
  9. // Number of periods when the container hit its throttling limit.
  10. ThrottledPeriods uint64 `json:"throttled_periods"`
  11. // Aggregate time the container was throttled for in nanoseconds.
  12. ThrottledTime uint64 `json:"throttled_time"`
  13. }
  14. // CPUUsage stores All CPU stats aggregated since container inception.
  15. type CPUUsage struct {
  16. // Total CPU time consumed.
  17. // Units: nanoseconds.
  18. TotalUsage uint64 `json:"total_usage"`
  19. // Total CPU time consumed per core.
  20. // Units: nanoseconds.
  21. PercpuUsage []uint64 `json:"percpu_usage"`
  22. // Time spent by tasks of the cgroup in kernel mode.
  23. // Units: nanoseconds.
  24. UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
  25. // Time spent by tasks of the cgroup in user mode.
  26. // Units: nanoseconds.
  27. UsageInUsermode uint64 `json:"usage_in_usermode"`
  28. }
  29. // CPUStats aggregates and wraps all CPU related info of container
  30. type CPUStats struct {
  31. CPUUsage CPUUsage `json:"cpu_usage"`
  32. SystemUsage uint64 `json:"system_cpu_usage"`
  33. ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
  34. }
  35. // MemoryStats aggregates All memory stats since container inception
  36. type MemoryStats struct {
  37. // current res_counter usage for memory
  38. Usage uint64 `json:"usage"`
  39. // maximum usage ever recorded.
  40. MaxUsage uint64 `json:"max_usage"`
  41. // TODO(vishh): Export these as stronger types.
  42. // all the stats exported via memory.stat.
  43. Stats map[string]uint64 `json:"stats"`
  44. // number of times memory usage hits limits.
  45. Failcnt uint64 `json:"failcnt"`
  46. Limit uint64 `json:"limit"`
  47. }
  48. // BlkioStatEntry is one small entity to store a piece of Blkio stats
  49. // TODO Windows: This can be factored out
  50. type BlkioStatEntry struct {
  51. Major uint64 `json:"major"`
  52. Minor uint64 `json:"minor"`
  53. Op string `json:"op"`
  54. Value uint64 `json:"value"`
  55. }
  56. // BlkioStats stores All IO service stats for data read and write
  57. // TODO Windows: This can be factored out
  58. type BlkioStats struct {
  59. // number of bytes transferred to and from the block device
  60. IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"`
  61. IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive"`
  62. IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive"`
  63. IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive"`
  64. IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive"`
  65. IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive"`
  66. IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive"`
  67. SectorsRecursive []BlkioStatEntry `json:"sectors_recursive"`
  68. }
  69. // NetworkStats aggregates All network stats of one container
  70. // TODO Windows: This will require refactoring
  71. type NetworkStats struct {
  72. RxBytes uint64 `json:"rx_bytes"`
  73. RxPackets uint64 `json:"rx_packets"`
  74. RxErrors uint64 `json:"rx_errors"`
  75. RxDropped uint64 `json:"rx_dropped"`
  76. TxBytes uint64 `json:"tx_bytes"`
  77. TxPackets uint64 `json:"tx_packets"`
  78. TxErrors uint64 `json:"tx_errors"`
  79. TxDropped uint64 `json:"tx_dropped"`
  80. }
  81. // Stats is Ultimate struct aggregating all types of stats of one container
  82. type Stats struct {
  83. Read time.Time `json:"read"`
  84. PreCPUStats CPUStats `json:"precpu_stats,omitempty"`
  85. CPUStats CPUStats `json:"cpu_stats,omitempty"`
  86. MemoryStats MemoryStats `json:"memory_stats,omitempty"`
  87. BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
  88. }
  89. // StatsJSON is newly used Networks
  90. type StatsJSON struct {
  91. Stats
  92. // Networks request version >=1.21
  93. Networks map[string]NetworkStats `json:"networks,omitempty"`
  94. }