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