stats.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 // import "github.com/docker/docker/api/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. // Online CPUs. Linux only.
  42. OnlineCPUs uint32 `json:"online_cpus,omitempty"`
  43. // Throttling Data. Linux only.
  44. ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
  45. }
  46. // MemoryStats aggregates all memory stats since container inception on Linux.
  47. // Windows returns stats for commit and private working set only.
  48. type MemoryStats struct {
  49. // Linux Memory Stats
  50. // current res_counter usage for memory
  51. Usage uint64 `json:"usage,omitempty"`
  52. // maximum usage ever recorded.
  53. MaxUsage uint64 `json:"max_usage,omitempty"`
  54. // TODO(vishh): Export these as stronger types.
  55. // all the stats exported via memory.stat.
  56. Stats map[string]uint64 `json:"stats,omitempty"`
  57. // number of times memory usage hits limits.
  58. Failcnt uint64 `json:"failcnt,omitempty"`
  59. Limit uint64 `json:"limit,omitempty"`
  60. // Windows Memory Stats
  61. // See https://technet.microsoft.com/en-us/magazine/ff382715.aspx
  62. // committed bytes
  63. Commit uint64 `json:"commitbytes,omitempty"`
  64. // peak committed bytes
  65. CommitPeak uint64 `json:"commitpeakbytes,omitempty"`
  66. // private working set
  67. PrivateWorkingSet uint64 `json:"privateworkingset,omitempty"`
  68. }
  69. // BlkioStatEntry is one small entity to store a piece of Blkio stats
  70. // Not used on Windows.
  71. type BlkioStatEntry struct {
  72. Major uint64 `json:"major"`
  73. Minor uint64 `json:"minor"`
  74. Op string `json:"op"`
  75. Value uint64 `json:"value"`
  76. }
  77. // BlkioStats stores All IO service stats for data read and write.
  78. // This is a Linux specific structure as the differences between expressing
  79. // block I/O on Windows and Linux are sufficiently significant to make
  80. // little sense attempting to morph into a combined structure.
  81. type BlkioStats struct {
  82. // number of bytes transferred to and from the block device
  83. IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"`
  84. IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive"`
  85. IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive"`
  86. IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive"`
  87. IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive"`
  88. IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive"`
  89. IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive"`
  90. SectorsRecursive []BlkioStatEntry `json:"sectors_recursive"`
  91. }
  92. // StorageStats is the disk I/O stats for read/write on Windows.
  93. type StorageStats struct {
  94. ReadCountNormalized uint64 `json:"read_count_normalized,omitempty"`
  95. ReadSizeBytes uint64 `json:"read_size_bytes,omitempty"`
  96. WriteCountNormalized uint64 `json:"write_count_normalized,omitempty"`
  97. WriteSizeBytes uint64 `json:"write_size_bytes,omitempty"`
  98. }
  99. // NetworkStats aggregates the network stats of one container
  100. type NetworkStats struct {
  101. // Bytes received. Windows and Linux.
  102. RxBytes uint64 `json:"rx_bytes"`
  103. // Packets received. Windows and Linux.
  104. RxPackets uint64 `json:"rx_packets"`
  105. // Received errors. Not used on Windows. Note that we don't `omitempty` this
  106. // field as it is expected in the >=v1.21 API stats structure.
  107. RxErrors uint64 `json:"rx_errors"`
  108. // Incoming packets dropped. Windows and Linux.
  109. RxDropped uint64 `json:"rx_dropped"`
  110. // Bytes sent. Windows and Linux.
  111. TxBytes uint64 `json:"tx_bytes"`
  112. // Packets sent. Windows and Linux.
  113. TxPackets uint64 `json:"tx_packets"`
  114. // Sent errors. Not used on Windows. Note that we don't `omitempty` this
  115. // field as it is expected in the >=v1.21 API stats structure.
  116. TxErrors uint64 `json:"tx_errors"`
  117. // Outgoing packets dropped. Windows and Linux.
  118. TxDropped uint64 `json:"tx_dropped"`
  119. // Endpoint ID. Not used on Linux.
  120. EndpointID string `json:"endpoint_id,omitempty"`
  121. // Instance ID. Not used on Linux.
  122. InstanceID string `json:"instance_id,omitempty"`
  123. }
  124. // PidsStats contains the stats of a container's pids
  125. type PidsStats struct {
  126. // Current is the number of pids in the cgroup
  127. Current uint64 `json:"current,omitempty"`
  128. // Limit is the hard limit on the number of pids in the cgroup.
  129. // A "Limit" of 0 means that there is no limit.
  130. Limit uint64 `json:"limit,omitempty"`
  131. }
  132. // Stats is Ultimate struct aggregating all types of stats of one container
  133. type Stats struct {
  134. // Common stats
  135. Read time.Time `json:"read"`
  136. PreRead time.Time `json:"preread"`
  137. // Linux specific stats, not populated on Windows.
  138. PidsStats PidsStats `json:"pids_stats,omitempty"`
  139. BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
  140. // Windows specific stats, not populated on Linux.
  141. NumProcs uint32 `json:"num_procs"`
  142. StorageStats StorageStats `json:"storage_stats,omitempty"`
  143. // Shared stats
  144. CPUStats CPUStats `json:"cpu_stats,omitempty"`
  145. PreCPUStats CPUStats `json:"precpu_stats,omitempty"` // "Pre"="Previous"
  146. MemoryStats MemoryStats `json:"memory_stats,omitempty"`
  147. }
  148. // StatsJSON is newly used Networks
  149. type StatsJSON struct {
  150. Stats
  151. Name string `json:"name,omitempty"`
  152. ID string `json:"id,omitempty"`
  153. // Networks request version >=1.21
  154. Networks map[string]NetworkStats `json:"networks,omitempty"`
  155. }