stats.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. // Not used on Windows.
  7. type ThrottlingData struct {
  8. // Number of periods with throttling active
  9. Periods uint64 `json:"periods"`
  10. // Number of periods when the container hits its throttling limit.
  11. ThrottledPeriods uint64 `json:"throttled_periods"`
  12. // Aggregate time the container was throttled for in nanoseconds.
  13. ThrottledTime uint64 `json:"throttled_time"`
  14. }
  15. // CPUUsage stores All CPU stats aggregated since container inception.
  16. type CPUUsage struct {
  17. // Total CPU time consumed.
  18. // Units: nanoseconds (Linux)
  19. // Units: 100's of nanoseconds (Windows)
  20. TotalUsage uint64 `json:"total_usage"`
  21. // Total CPU time consumed per core (Linux). Not used on Windows.
  22. // Units: nanoseconds.
  23. PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
  24. // Time spent by tasks of the cgroup in kernel mode (Linux).
  25. // Time spent by all container processes in kernel mode (Windows).
  26. // Units: nanoseconds (Linux).
  27. // Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers.
  28. UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
  29. // Time spent by tasks of the cgroup in user mode (Linux).
  30. // Time spent by all container processes in user mode (Windows).
  31. // Units: nanoseconds (Linux).
  32. // Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers
  33. UsageInUsermode uint64 `json:"usage_in_usermode"`
  34. }
  35. // CPUStats aggregates and wraps all CPU related info of container
  36. type CPUStats struct {
  37. // CPU Usage. Linux and Windows.
  38. CPUUsage CPUUsage `json:"cpu_usage"`
  39. // System Usage. Linux only.
  40. SystemUsage uint64 `json:"system_cpu_usage,omitempty"`
  41. // Throttling Data. Linux only.
  42. ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
  43. }
  44. // MemoryStats aggregates all memory stats since container inception on Linux.
  45. // Windows returns stats for commit and private working set only.
  46. type MemoryStats struct {
  47. // Linux Memory Stats
  48. // current res_counter usage for memory
  49. Usage uint64 `json:"usage,omitempty"`
  50. // maximum usage ever recorded.
  51. MaxUsage uint64 `json:"max_usage,omitempty"`
  52. // TODO(vishh): Export these as stronger types.
  53. // all the stats exported via memory.stat.
  54. Stats map[string]uint64 `json:"stats,omitempty"`
  55. // number of times memory usage hits limits.
  56. Failcnt uint64 `json:"failcnt,omitempty"`
  57. Limit uint64 `json:"limit,omitempty"`
  58. // Windows Memory Stats
  59. // See https://technet.microsoft.com/en-us/magazine/ff382715.aspx
  60. // committed bytes
  61. Commit uint64 `json:"commitbytes,omitempty"`
  62. // peak committed bytes
  63. CommitPeak uint64 `json:"commitpeakbytes,omitempty"`
  64. // private working set
  65. PrivateWorkingSet uint64 `json:"privateworkingset,omitempty"`
  66. }
  67. // BlkioStatEntry is one small entity to store a piece of Blkio stats
  68. // Not used on Windows.
  69. type BlkioStatEntry struct {
  70. Major uint64 `json:"major"`
  71. Minor uint64 `json:"minor"`
  72. Op string `json:"op"`
  73. Value uint64 `json:"value"`
  74. }
  75. // BlkioStats stores All IO service stats for data read and write.
  76. // This is a Linux specific structure as the differences between expressing
  77. // block I/O on Windows and Linux are sufficiently significant to make
  78. // little sense attempting to morph into a combined structure.
  79. type BlkioStats struct {
  80. // number of bytes transferred to and from the block device
  81. IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"`
  82. IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive"`
  83. IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive"`
  84. IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive"`
  85. IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive"`
  86. IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive"`
  87. IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive"`
  88. SectorsRecursive []BlkioStatEntry `json:"sectors_recursive"`
  89. }
  90. // StorageStats is the disk I/O stats for read/write on Windows.
  91. type StorageStats struct {
  92. ReadCountNormalized uint64 `json:"read_count_normalized,omitempty"`
  93. ReadSizeBytes uint64 `json:"read_size_bytes,omitempty"`
  94. WriteCountNormalized uint64 `json:"write_count_normalized,omitempty"`
  95. WriteSizeBytes uint64 `json:"write_size_bytes,omitempty"`
  96. }
  97. // NetworkStats aggregates the network stats of one container
  98. type NetworkStats struct {
  99. // Bytes received. Windows and Linux.
  100. RxBytes uint64 `json:"rx_bytes"`
  101. // Packets received. Windows and Linux.
  102. RxPackets uint64 `json:"rx_packets"`
  103. // Received errors. Not used on Windows. Note that we dont `omitempty` this
  104. // field as it is expected in the >=v1.21 API stats structure.
  105. RxErrors uint64 `json:"rx_errors"`
  106. // Incoming packets dropped. Windows and Linux.
  107. RxDropped uint64 `json:"rx_dropped"`
  108. // Bytes sent. Windows and Linux.
  109. TxBytes uint64 `json:"tx_bytes"`
  110. // Packets sent. Windows and Linux.
  111. TxPackets uint64 `json:"tx_packets"`
  112. // Sent errors. Not used on Windows. Note that we dont `omitempty` this
  113. // field as it is expected in the >=v1.21 API stats structure.
  114. TxErrors uint64 `json:"tx_errors"`
  115. // Outgoing packets dropped. Windows and Linux.
  116. TxDropped uint64 `json:"tx_dropped"`
  117. // Endpoint ID. Not used on Linux.
  118. EndpointID string `json:"endpoint_id,omitempty"`
  119. // Instance ID. Not used on Linux.
  120. InstanceID string `json:"instance_id,omitempty"`
  121. }
  122. // PidsStats contains the stats of a container's pids
  123. type PidsStats struct {
  124. // Current is the number of pids in the cgroup
  125. Current uint64 `json:"current,omitempty"`
  126. // Limit is the hard limit on the number of pids in the cgroup.
  127. // A "Limit" of 0 means that there is no limit.
  128. Limit uint64 `json:"limit,omitempty"`
  129. }
  130. // Stats is Ultimate struct aggregating all types of stats of one container
  131. type Stats struct {
  132. // Common stats
  133. Read time.Time `json:"read"`
  134. PreRead time.Time `json:"preread"`
  135. // Linux specific stats, not populated on Windows.
  136. PidsStats PidsStats `json:"pids_stats,omitempty"`
  137. BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
  138. // Windows specific stats, not populated on Linux.
  139. NumProcs uint32 `json:"num_procs"`
  140. StorageStats StorageStats `json:"storage_stats,omitempty"`
  141. // Shared stats
  142. CPUStats CPUStats `json:"cpu_stats,omitempty"`
  143. PreCPUStats CPUStats `json:"precpu_stats,omitempty"` // "Pre"="Previous"
  144. MemoryStats MemoryStats `json:"memory_stats,omitempty"`
  145. }
  146. // StatsJSON is newly used Networks
  147. type StatsJSON struct {
  148. Stats
  149. Name string `json:"name,omitempty"`
  150. ID string `json:"id,omitempty"`
  151. // Networks request version >=1.21
  152. Networks map[string]NetworkStats `json:"networks,omitempty"`
  153. }