github.com/google/cadvisor@v0.49.1/info/v2/container.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package v2 16 17 import ( 18 "time" 19 20 // TODO(rjnagal): Remove dependency after moving all stats structs from v1. 21 // using v1 now for easy conversion. 22 v1 "github.com/google/cadvisor/info/v1" 23 ) 24 25 const ( 26 TypeName = "name" 27 TypeDocker = "docker" 28 TypePodman = "podman" 29 ) 30 31 type CpuSpec struct { 32 // Requested cpu shares. Default is 1024. 33 Limit uint64 `json:"limit"` 34 // Requested cpu hard limit. Default is unlimited (0). 35 // Units: milli-cpus. 36 MaxLimit uint64 `json:"max_limit"` 37 // Cpu affinity mask. 38 // TODO(rjnagal): Add a library to convert mask string to set of cpu bitmask. 39 Mask string `json:"mask,omitempty"` 40 // CPUQuota Default is disabled 41 Quota uint64 `json:"quota,omitempty"` 42 // Period is the CPU reference time in ns e.g the quota is compared against this. 43 Period uint64 `json:"period,omitempty"` 44 } 45 46 type MemorySpec struct { 47 // The amount of memory requested. Default is unlimited (-1). 48 // Units: bytes. 49 Limit uint64 `json:"limit,omitempty"` 50 51 // The amount of guaranteed memory. Default is 0. 52 // Units: bytes. 53 Reservation uint64 `json:"reservation,omitempty"` 54 55 // The amount of swap space requested. Default is unlimited (-1). 56 // Units: bytes. 57 SwapLimit uint64 `json:"swap_limit,omitempty"` 58 } 59 60 type ContainerInfo struct { 61 // Describes the container. 62 Spec ContainerSpec `json:"spec,omitempty"` 63 64 // Historical statistics gathered from the container. 65 Stats []*ContainerStats `json:"stats,omitempty"` 66 } 67 68 type ContainerSpec struct { 69 // Time at which the container was created. 70 CreationTime time.Time `json:"creation_time,omitempty"` 71 72 // Other names by which the container is known within a certain namespace. 73 // This is unique within that namespace. 74 Aliases []string `json:"aliases,omitempty"` 75 76 // Namespace under which the aliases of a container are unique. 77 // An example of a namespace is "docker" for Docker containers. 78 Namespace string `json:"namespace,omitempty"` 79 80 // Metadata labels associated with this container. 81 Labels map[string]string `json:"labels,omitempty"` 82 // Metadata envs associated with this container. Only whitelisted envs are added. 83 Envs map[string]string `json:"envs,omitempty"` 84 85 HasCpu bool `json:"has_cpu"` 86 Cpu CpuSpec `json:"cpu,omitempty"` 87 88 HasMemory bool `json:"has_memory"` 89 Memory MemorySpec `json:"memory,omitempty"` 90 91 HasHugetlb bool `json:"has_hugetlb"` 92 93 HasCustomMetrics bool `json:"has_custom_metrics"` 94 CustomMetrics []v1.MetricSpec `json:"custom_metrics,omitempty"` 95 96 HasProcesses bool `json:"has_processes"` 97 Processes v1.ProcessSpec `json:"processes,omitempty"` 98 99 // Following resources have no associated spec, but are being isolated. 100 HasNetwork bool `json:"has_network"` 101 HasFilesystem bool `json:"has_filesystem"` 102 HasDiskIo bool `json:"has_diskio"` 103 104 // Image name used for this container. 105 Image string `json:"image,omitempty"` 106 } 107 108 type DeprecatedContainerStats struct { 109 // The time of this stat point. 110 Timestamp time.Time `json:"timestamp"` 111 // CPU statistics 112 HasCpu bool `json:"has_cpu"` 113 // In nanoseconds (aggregated) 114 Cpu v1.CpuStats `json:"cpu,omitempty"` 115 // In nanocores per second (instantaneous) 116 CpuInst *CpuInstStats `json:"cpu_inst,omitempty"` 117 // Disk IO statistics 118 HasDiskIo bool `json:"has_diskio"` 119 DiskIo v1.DiskIoStats `json:"diskio,omitempty"` 120 // Memory statistics 121 HasMemory bool `json:"has_memory"` 122 Memory v1.MemoryStats `json:"memory,omitempty"` 123 // Hugepage statistics 124 HasHugetlb bool `json:"has_hugetlb"` 125 Hugetlb map[string]v1.HugetlbStats `json:"hugetlb,omitempty"` 126 // Network statistics 127 HasNetwork bool `json:"has_network"` 128 Network NetworkStats `json:"network,omitempty"` 129 // Processes statistics 130 HasProcesses bool `json:"has_processes"` 131 Processes v1.ProcessStats `json:"processes,omitempty"` 132 // Filesystem statistics 133 HasFilesystem bool `json:"has_filesystem"` 134 Filesystem []v1.FsStats `json:"filesystem,omitempty"` 135 // Task load statistics 136 HasLoad bool `json:"has_load"` 137 Load v1.LoadStats `json:"load_stats,omitempty"` 138 // Custom Metrics 139 HasCustomMetrics bool `json:"has_custom_metrics"` 140 CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"` 141 // Perf events counters 142 PerfStats []v1.PerfStat `json:"perf_stats,omitempty"` 143 // Statistics originating from perf uncore events. 144 // Applies only for root container. 145 PerfUncoreStats []v1.PerfUncoreStat `json:"perf_uncore_stats,omitempty"` 146 // Referenced memory 147 ReferencedMemory uint64 `json:"referenced_memory,omitempty"` 148 // Resource Control (resctrl) statistics 149 Resctrl v1.ResctrlStats `json:"resctrl,omitempty"` 150 } 151 152 type ContainerStats struct { 153 // The time of this stat point. 154 Timestamp time.Time `json:"timestamp"` 155 // CPU statistics 156 // In nanoseconds (aggregated) 157 Cpu *v1.CpuStats `json:"cpu,omitempty"` 158 // In nanocores per second (instantaneous) 159 CpuInst *CpuInstStats `json:"cpu_inst,omitempty"` 160 // Disk IO statistics 161 DiskIo *v1.DiskIoStats `json:"diskio,omitempty"` 162 // Memory statistics 163 Memory *v1.MemoryStats `json:"memory,omitempty"` 164 // Hugepage statistics 165 Hugetlb *map[string]v1.HugetlbStats `json:"hugetlb,omitempty"` 166 // Network statistics 167 Network *NetworkStats `json:"network,omitempty"` 168 // Processes statistics 169 Processes *v1.ProcessStats `json:"processes,omitempty"` 170 // Filesystem statistics 171 Filesystem *FilesystemStats `json:"filesystem,omitempty"` 172 // Task load statistics 173 Load *v1.LoadStats `json:"load_stats,omitempty"` 174 // Metrics for Accelerators. Each Accelerator corresponds to one element in the array. 175 Accelerators []v1.AcceleratorStats `json:"accelerators,omitempty"` 176 // Custom Metrics 177 CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"` 178 // Perf events counters 179 PerfStats []v1.PerfStat `json:"perf_stats,omitempty"` 180 // Statistics originating from perf uncore events. 181 // Applies only for root container. 182 PerfUncoreStats []v1.PerfUncoreStat `json:"perf_uncore_stats,omitempty"` 183 // Referenced memory 184 ReferencedMemory uint64 `json:"referenced_memory,omitempty"` 185 // Resource Control (resctrl) statistics 186 Resctrl v1.ResctrlStats `json:"resctrl,omitempty"` 187 } 188 189 type Percentiles struct { 190 // Indicates whether the stats are present or not. 191 // If true, values below do not have any data. 192 Present bool `json:"present"` 193 // Average over the collected sample. 194 Mean uint64 `json:"mean"` 195 // Max seen over the collected sample. 196 Max uint64 `json:"max"` 197 // 50th percentile over the collected sample. 198 Fifty uint64 `json:"fifty"` 199 // 90th percentile over the collected sample. 200 Ninety uint64 `json:"ninety"` 201 // 95th percentile over the collected sample. 202 NinetyFive uint64 `json:"ninetyfive"` 203 } 204 205 type Usage struct { 206 // Indicates amount of data available [0-100]. 207 // If we have data for half a day, we'll still process DayUsage, 208 // but set PercentComplete to 50. 209 PercentComplete int32 `json:"percent_complete"` 210 // Mean, Max, and 90p cpu rate value in milliCpus/seconds. Converted to milliCpus to avoid floats. 211 Cpu Percentiles `json:"cpu"` 212 // Mean, Max, and 90p memory size in bytes. 213 Memory Percentiles `json:"memory"` 214 } 215 216 // latest sample collected for a container. 217 type InstantUsage struct { 218 // cpu rate in cpu milliseconds/second. 219 Cpu uint64 `json:"cpu"` 220 // Memory usage in bytes. 221 Memory uint64 `json:"memory"` 222 } 223 224 type DerivedStats struct { 225 // Time of generation of these stats. 226 Timestamp time.Time `json:"timestamp"` 227 // Latest instantaneous sample. 228 LatestUsage InstantUsage `json:"latest_usage"` 229 // Percentiles in last observed minute. 230 MinuteUsage Usage `json:"minute_usage"` 231 // Percentile in last hour. 232 HourUsage Usage `json:"hour_usage"` 233 // Percentile in last day. 234 DayUsage Usage `json:"day_usage"` 235 } 236 237 type FsInfo struct { 238 // Time of generation of these stats. 239 Timestamp time.Time `json:"timestamp"` 240 241 // The block device name associated with the filesystem. 242 Device string `json:"device"` 243 244 // Path where the filesystem is mounted. 245 Mountpoint string `json:"mountpoint"` 246 247 // Filesystem usage in bytes. 248 Capacity uint64 `json:"capacity"` 249 250 // Bytes available for non-root use. 251 Available uint64 `json:"available"` 252 253 // Number of bytes used on this filesystem. 254 Usage uint64 `json:"usage"` 255 256 // Labels associated with this filesystem. 257 Labels []string `json:"labels"` 258 259 // Number of Inodes. 260 Inodes *uint64 `json:"inodes,omitempty"` 261 262 // Number of available Inodes (if known) 263 InodesFree *uint64 `json:"inodes_free,omitempty"` 264 } 265 266 type RequestOptions struct { 267 // Type of container identifier specified - TypeName (default) or TypeDocker 268 IdType string `json:"type"` 269 // Number of stats to return, -1 means no limit. 270 Count int `json:"count"` 271 // Whether to include stats for child subcontainers. 272 Recursive bool `json:"recursive"` 273 // Update stats if they are older than MaxAge 274 // nil indicates no update, and 0 will always trigger an update. 275 MaxAge *time.Duration `json:"max_age"` 276 } 277 278 type ProcessInfo struct { 279 User string `json:"user"` 280 Pid int `json:"pid"` 281 Ppid int `json:"parent_pid"` 282 StartTime string `json:"start_time"` 283 PercentCpu float32 `json:"percent_cpu"` 284 PercentMemory float32 `json:"percent_mem"` 285 RSS uint64 `json:"rss"` 286 VirtualSize uint64 `json:"virtual_size"` 287 Status string `json:"status"` 288 RunningTime string `json:"running_time"` 289 CgroupPath string `json:"cgroup_path"` 290 Cmd string `json:"cmd"` 291 FdCount int `json:"fd_count"` 292 Psr int `json:"psr"` 293 } 294 295 type TcpStat struct { 296 Established uint64 297 SynSent uint64 298 SynRecv uint64 299 FinWait1 uint64 300 FinWait2 uint64 301 TimeWait uint64 302 Close uint64 303 CloseWait uint64 304 LastAck uint64 305 Listen uint64 306 Closing uint64 307 } 308 309 type NetworkStats struct { 310 // Network stats by interface. 311 Interfaces []v1.InterfaceStats `json:"interfaces,omitempty"` 312 // TCP connection stats (Established, Listen...) 313 Tcp TcpStat `json:"tcp"` 314 // TCP6 connection stats (Established, Listen...) 315 Tcp6 TcpStat `json:"tcp6"` 316 // UDP connection stats 317 Udp v1.UdpStat `json:"udp"` 318 // UDP6 connection stats 319 Udp6 v1.UdpStat `json:"udp6"` 320 // TCP advanced stats 321 TcpAdvanced v1.TcpAdvancedStat `json:"tcp_advanced"` 322 } 323 324 // Instantaneous CPU stats 325 type CpuInstStats struct { 326 Usage CpuInstUsage `json:"usage"` 327 } 328 329 // CPU usage time statistics. 330 type CpuInstUsage struct { 331 // Total CPU usage. 332 // Units: nanocores per second 333 Total uint64 `json:"total"` 334 335 // Per CPU/core usage of the container. 336 // Unit: nanocores per second 337 PerCpu []uint64 `json:"per_cpu_usage,omitempty"` 338 339 // Time spent in user space. 340 // Unit: nanocores per second 341 User uint64 `json:"user"` 342 343 // Time spent in kernel space. 344 // Unit: nanocores per second 345 System uint64 `json:"system"` 346 } 347 348 // Filesystem usage statistics. 349 type FilesystemStats struct { 350 // Total Number of bytes consumed by container. 351 TotalUsageBytes *uint64 `json:"totalUsageBytes,omitempty"` 352 // Number of bytes consumed by a container through its root filesystem. 353 BaseUsageBytes *uint64 `json:"baseUsageBytes,omitempty"` 354 // Number of inodes used within the container's root filesystem. 355 // This only accounts for inodes that are shared across containers, 356 // and does not include inodes used in mounted directories. 357 InodeUsage *uint64 `json:"containter_inode_usage,omitempty"` 358 }