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