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 15package v2 16 17import ( 18 "time" 19 20 // TODO(rjnagal): Remove dependency after moving all stats structs from v1. 21 // using v1 now for easy conversion. 22 "github.com/google/cadvisor/info/v1" 23) 24 25const ( 26 TypeName = "name" 27 TypeDocker = "docker" 28) 29 30type CpuSpec struct { 31 // Requested cpu shares. Default is 1024. 32 Limit uint64 `json:"limit"` 33 // Requested cpu hard limit. Default is unlimited (0). 34 // Units: milli-cpus. 35 MaxLimit uint64 `json:"max_limit"` 36 // Cpu affinity mask. 37 // TODO(rjnagal): Add a library to convert mask string to set of cpu bitmask. 38 Mask string `json:"mask,omitempty"` 39 // CPUQuota Default is disabled 40 Quota uint64 `json:"quota,omitempty"` 41 // Period is the CPU reference time in ns e.g the quota is compared aginst this. 42 Period uint64 `json:"period,omitempty"` 43} 44 45type MemorySpec struct { 46 // The amount of memory requested. Default is unlimited (-1). 47 // Units: bytes. 48 Limit uint64 `json:"limit,omitempty"` 49 50 // The amount of guaranteed memory. Default is 0. 51 // Units: bytes. 52 Reservation uint64 `json:"reservation,omitempty"` 53 54 // The amount of swap space requested. Default is unlimited (-1). 55 // Units: bytes. 56 SwapLimit uint64 `json:"swap_limit,omitempty"` 57} 58 59type ContainerInfo struct { 60 // Describes the container. 61 Spec ContainerSpec `json:"spec,omitempty"` 62 63 // Historical statistics gathered from the container. 64 Stats []*ContainerStats `json:"stats,omitempty"` 65} 66 67type ContainerSpec struct { 68 // Time at which the container was created. 69 CreationTime time.Time `json:"creation_time,omitempty"` 70 71 // Other names by which the container is known within a certain namespace. 72 // This is unique within that namespace. 73 Aliases []string `json:"aliases,omitempty"` 74 75 // Namespace under which the aliases of a container are unique. 76 // An example of a namespace is "docker" for Docker containers. 77 Namespace string `json:"namespace,omitempty"` 78 79 // Metadata labels associated with this container. 80 Labels map[string]string `json:"labels,omitempty"` 81 // Metadata envs associated with this container. Only whitelisted envs are added. 82 Envs map[string]string `json:"envs,omitempty"` 83 84 HasCpu bool `json:"has_cpu"` 85 Cpu CpuSpec `json:"cpu,omitempty"` 86 87 HasMemory bool `json:"has_memory"` 88 Memory MemorySpec `json:"memory,omitempty"` 89 90 HasCustomMetrics bool `json:"has_custom_metrics"` 91 CustomMetrics []v1.MetricSpec `json:"custom_metrics,omitempty"` 92 93 // Following resources have no associated spec, but are being isolated. 94 HasNetwork bool `json:"has_network"` 95 HasFilesystem bool `json:"has_filesystem"` 96 HasDiskIo bool `json:"has_diskio"` 97 98 // Image name used for this container. 99 Image string `json:"image,omitempty"` 100} 101 102type DeprecatedContainerStats struct { 103 // The time of this stat point. 104 Timestamp time.Time `json:"timestamp"` 105 // CPU statistics 106 HasCpu bool `json:"has_cpu"` 107 // In nanoseconds (aggregated) 108 Cpu v1.CpuStats `json:"cpu,omitempty"` 109 // In nanocores per second (instantaneous) 110 CpuInst *CpuInstStats `json:"cpu_inst,omitempty"` 111 // Disk IO statistics 112 HasDiskIo bool `json:"has_diskio"` 113 DiskIo v1.DiskIoStats `json:"diskio,omitempty"` 114 // Memory statistics 115 HasMemory bool `json:"has_memory"` 116 Memory v1.MemoryStats `json:"memory,omitempty"` 117 // Network statistics 118 HasNetwork bool `json:"has_network"` 119 Network NetworkStats `json:"network,omitempty"` 120 // Filesystem statistics 121 HasFilesystem bool `json:"has_filesystem"` 122 Filesystem []v1.FsStats `json:"filesystem,omitempty"` 123 // Task load statistics 124 HasLoad bool `json:"has_load"` 125 Load v1.LoadStats `json:"load_stats,omitempty"` 126 // Custom Metrics 127 HasCustomMetrics bool `json:"has_custom_metrics"` 128 CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"` 129} 130 131type ContainerStats struct { 132 // The time of this stat point. 133 Timestamp time.Time `json:"timestamp"` 134 // CPU statistics 135 // In nanoseconds (aggregated) 136 Cpu *v1.CpuStats `json:"cpu,omitempty"` 137 // In nanocores per second (instantaneous) 138 CpuInst *CpuInstStats `json:"cpu_inst,omitempty"` 139 // Disk IO statistics 140 DiskIo *v1.DiskIoStats `json:"diskio,omitempty"` 141 // Memory statistics 142 Memory *v1.MemoryStats `json:"memory,omitempty"` 143 // Network statistics 144 Network *NetworkStats `json:"network,omitempty"` 145 // Filesystem statistics 146 Filesystem *FilesystemStats `json:"filesystem,omitempty"` 147 // Task load statistics 148 Load *v1.LoadStats `json:"load_stats,omitempty"` 149 // Custom Metrics 150 CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"` 151} 152 153type Percentiles struct { 154 // Indicates whether the stats are present or not. 155 // If true, values below do not have any data. 156 Present bool `json:"present"` 157 // Average over the collected sample. 158 Mean uint64 `json:"mean"` 159 // Max seen over the collected sample. 160 Max uint64 `json:"max"` 161 // 50th percentile over the collected sample. 162 Fifty uint64 `json:"fifty"` 163 // 90th percentile over the collected sample. 164 Ninety uint64 `json:"ninety"` 165 // 95th percentile over the collected sample. 166 NinetyFive uint64 `json:"ninetyfive"` 167} 168 169type Usage struct { 170 // Indicates amount of data available [0-100]. 171 // If we have data for half a day, we'll still process DayUsage, 172 // but set PercentComplete to 50. 173 PercentComplete int32 `json:"percent_complete"` 174 // Mean, Max, and 90p cpu rate value in milliCpus/seconds. Converted to milliCpus to avoid floats. 175 Cpu Percentiles `json:"cpu"` 176 // Mean, Max, and 90p memory size in bytes. 177 Memory Percentiles `json:"memory"` 178} 179 180// latest sample collected for a container. 181type InstantUsage struct { 182 // cpu rate in cpu milliseconds/second. 183 Cpu uint64 `json:"cpu"` 184 // Memory usage in bytes. 185 Memory uint64 `json:"memory"` 186} 187 188type DerivedStats struct { 189 // Time of generation of these stats. 190 Timestamp time.Time `json:"timestamp"` 191 // Latest instantaneous sample. 192 LatestUsage InstantUsage `json:"latest_usage"` 193 // Percentiles in last observed minute. 194 MinuteUsage Usage `json:"minute_usage"` 195 // Percentile in last hour. 196 HourUsage Usage `json:"hour_usage"` 197 // Percentile in last day. 198 DayUsage Usage `json:"day_usage"` 199} 200 201type FsInfo struct { 202 // The block device name associated with the filesystem. 203 Device string `json:"device"` 204 205 // Path where the filesystem is mounted. 206 Mountpoint string `json:"mountpoint"` 207 208 // Filesystem usage in bytes. 209 Capacity uint64 `json:"capacity"` 210 211 // Bytes available for non-root use. 212 Available uint64 `json:"available"` 213 214 // Number of bytes used on this filesystem. 215 Usage uint64 `json:"usage"` 216 217 // Labels associated with this filesystem. 218 Labels []string `json:"labels"` 219} 220 221type RequestOptions struct { 222 // Type of container identifier specified - "name", "dockerid", dockeralias" 223 IdType string `json:"type"` 224 // Number of stats to return 225 Count int `json:"count"` 226 // Whether to include stats for child subcontainers. 227 Recursive bool `json:"recursive"` 228} 229 230type ProcessInfo struct { 231 User string `json:"user"` 232 Pid int `json:"pid"` 233 Ppid int `json:"parent_pid"` 234 StartTime string `json:"start_time"` 235 PercentCpu float32 `json:"percent_cpu"` 236 PercentMemory float32 `json:"percent_mem"` 237 RSS uint64 `json:"rss"` 238 VirtualSize uint64 `json:"virtual_size"` 239 Status string `json:"status"` 240 RunningTime string `json:"running_time"` 241 CgroupPath string `json:"cgroup_path"` 242 Cmd string `json:"cmd"` 243} 244 245type TcpStat struct { 246 Established uint64 247 SynSent uint64 248 SynRecv uint64 249 FinWait1 uint64 250 FinWait2 uint64 251 TimeWait uint64 252 Close uint64 253 CloseWait uint64 254 LastAck uint64 255 Listen uint64 256 Closing uint64 257} 258 259type NetworkStats struct { 260 // Network stats by interface. 261 Interfaces []v1.InterfaceStats `json:"interfaces,omitempty"` 262 // TCP connection stats (Established, Listen...) 263 Tcp TcpStat `json:"tcp"` 264 // TCP6 connection stats (Established, Listen...) 265 Tcp6 TcpStat `json:"tcp6"` 266} 267 268// Instantaneous CPU stats 269type CpuInstStats struct { 270 Usage CpuInstUsage `json:"usage"` 271} 272 273// CPU usage time statistics. 274type CpuInstUsage struct { 275 // Total CPU usage. 276 // Units: nanocores per second 277 Total uint64 `json:"total"` 278 279 // Per CPU/core usage of the container. 280 // Unit: nanocores per second 281 PerCpu []uint64 `json:"per_cpu_usage,omitempty"` 282 283 // Time spent in user space. 284 // Unit: nanocores per second 285 User uint64 `json:"user"` 286 287 // Time spent in kernel space. 288 // Unit: nanocores per second 289 System uint64 `json:"system"` 290} 291 292// Filesystem usage statistics. 293type FilesystemStats struct { 294 // Total Number of bytes consumed by container. 295 TotalUsageBytes *uint64 `json:"totalUsageBytes,omitempty"` 296 // Number of bytes consumed by a container through its root filesystem. 297 BaseUsageBytes *uint64 `json:"baseUsageBytes,omitempty"` 298} 299