blob: ecffb8bc344952e7c5822b23fde9df8cb3d15087 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2015 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1alpha1
18
19import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21)
22
23// Summary is a top-level container for holding NodeStats and PodStats.
24type Summary struct {
25 // Overall node stats.
26 Node NodeStats `json:"node"`
27 // Per-pod stats.
28 Pods []PodStats `json:"pods"`
29}
30
31// NodeStats holds node-level unprocessed sample stats.
32type NodeStats struct {
33 // Reference to the measured Node.
34 NodeName string `json:"nodeName"`
35 // Stats of system daemons tracked as raw containers.
36 // The system containers are named according to the SystemContainer* constants.
37 // +optional
38 // +patchMergeKey=name
39 // +patchStrategy=merge
40 SystemContainers []ContainerStats `json:"systemContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
41 // The time at which data collection for the node-scoped (i.e. aggregate) stats was (re)started.
42 StartTime metav1.Time `json:"startTime"`
43 // Stats pertaining to CPU resources.
44 // +optional
45 CPU *CPUStats `json:"cpu,omitempty"`
46 // Stats pertaining to memory (RAM) resources.
47 // +optional
48 Memory *MemoryStats `json:"memory,omitempty"`
49 // Stats pertaining to network resources.
50 // +optional
51 Network *NetworkStats `json:"network,omitempty"`
52 // Stats pertaining to total usage of filesystem resources on the rootfs used by node k8s components.
53 // NodeFs.Used is the total bytes used on the filesystem.
54 // +optional
55 Fs *FsStats `json:"fs,omitempty"`
56 // Stats about the underlying container runtime.
57 // +optional
58 Runtime *RuntimeStats `json:"runtime,omitempty"`
59 // Stats about the rlimit of system.
60 // +optional
61 Rlimit *RlimitStats `json:"rlimit,omitempty"`
62}
63
64// RlimitStats are stats rlimit of OS.
65type RlimitStats struct {
66 Time metav1.Time `json:"time"`
67
68 // The max PID of OS.
69 MaxPID *int64 `json:"maxpid,omitempty"`
70 // The number of running process in the OS.
71 NumOfRunningProcesses *int64 `json:"curproc,omitempty"`
72}
73
74// RuntimeStats are stats pertaining to the underlying container runtime.
75type RuntimeStats struct {
76 // Stats about the underlying filesystem where container images are stored.
77 // This filesystem could be the same as the primary (root) filesystem.
78 // Usage here refers to the total number of bytes occupied by images on the filesystem.
79 // +optional
80 ImageFs *FsStats `json:"imageFs,omitempty"`
81}
82
83const (
84 // SystemContainerKubelet is the container name for the system container tracking Kubelet usage.
85 SystemContainerKubelet = "kubelet"
86 // SystemContainerRuntime is the container name for the system container tracking the runtime (e.g. docker) usage.
87 SystemContainerRuntime = "runtime"
88 // SystemContainerMisc is the container name for the system container tracking non-kubernetes processes.
89 SystemContainerMisc = "misc"
90 // SystemContainerPods is the container name for the system container tracking user pods.
91 SystemContainerPods = "pods"
92)
93
94// PodStats holds pod-level unprocessed sample stats.
95type PodStats struct {
96 // Reference to the measured Pod.
97 PodRef PodReference `json:"podRef"`
98 // The time at which data collection for the pod-scoped (e.g. network) stats was (re)started.
99 StartTime metav1.Time `json:"startTime"`
100 // Stats of containers in the measured pod.
101 // +patchMergeKey=name
102 // +patchStrategy=merge
103 Containers []ContainerStats `json:"containers" patchStrategy:"merge" patchMergeKey:"name"`
104 // Stats pertaining to CPU resources consumed by pod cgroup (which includes all containers' resource usage and pod overhead).
105 // +optional
106 CPU *CPUStats `json:"cpu,omitempty"`
107 // Stats pertaining to memory (RAM) resources consumed by pod cgroup (which includes all containers' resource usage and pod overhead).
108 // +optional
109 Memory *MemoryStats `json:"memory,omitempty"`
110 // Stats pertaining to network resources.
111 // +optional
112 Network *NetworkStats `json:"network,omitempty"`
113 // Stats pertaining to volume usage of filesystem resources.
114 // VolumeStats.UsedBytes is the number of bytes used by the Volume
115 // +optional
116 // +patchMergeKey=name
117 // +patchStrategy=merge
118 VolumeStats []VolumeStats `json:"volume,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
119 // EphemeralStorage reports the total filesystem usage for the containers and emptyDir-backed volumes in the measured Pod.
120 // +optional
121 EphemeralStorage *FsStats `json:"ephemeral-storage,omitempty"`
122}
123
124// ContainerStats holds container-level unprocessed sample stats.
125type ContainerStats struct {
126 // Reference to the measured container.
127 Name string `json:"name"`
128 // The time at which data collection for this container was (re)started.
129 StartTime metav1.Time `json:"startTime"`
130 // Stats pertaining to CPU resources.
131 // +optional
132 CPU *CPUStats `json:"cpu,omitempty"`
133 // Stats pertaining to memory (RAM) resources.
134 // +optional
135 Memory *MemoryStats `json:"memory,omitempty"`
136 // Metrics for Accelerators. Each Accelerator corresponds to one element in the array.
137 Accelerators []AcceleratorStats `json:"accelerators,omitempty"`
138 // Stats pertaining to container rootfs usage of filesystem resources.
139 // Rootfs.UsedBytes is the number of bytes used for the container write layer.
140 // +optional
141 Rootfs *FsStats `json:"rootfs,omitempty"`
142 // Stats pertaining to container logs usage of filesystem resources.
143 // Logs.UsedBytes is the number of bytes used for the container logs.
144 // +optional
145 Logs *FsStats `json:"logs,omitempty"`
146 // User defined metrics that are exposed by containers in the pod. Typically, we expect only one container in the pod to be exposing user defined metrics. In the event of multiple containers exposing metrics, they will be combined here.
147 // +patchMergeKey=name
148 // +patchStrategy=merge
149 UserDefinedMetrics []UserDefinedMetric `json:"userDefinedMetrics,omitmepty" patchStrategy:"merge" patchMergeKey:"name"`
150}
151
152// PodReference contains enough information to locate the referenced pod.
153type PodReference struct {
154 Name string `json:"name"`
155 Namespace string `json:"namespace"`
156 UID string `json:"uid"`
157}
158
159// InterfaceStats contains resource value data about interface.
160type InterfaceStats struct {
161 // The name of the interface
162 Name string `json:"name"`
163 // Cumulative count of bytes received.
164 // +optional
165 RxBytes *uint64 `json:"rxBytes,omitempty"`
166 // Cumulative count of receive errors encountered.
167 // +optional
168 RxErrors *uint64 `json:"rxErrors,omitempty"`
169 // Cumulative count of bytes transmitted.
170 // +optional
171 TxBytes *uint64 `json:"txBytes,omitempty"`
172 // Cumulative count of transmit errors encountered.
173 // +optional
174 TxErrors *uint64 `json:"txErrors,omitempty"`
175}
176
177// NetworkStats contains data about network resources.
178type NetworkStats struct {
179 // The time at which these stats were updated.
180 Time metav1.Time `json:"time"`
181
182 // Stats for the default interface, if found
183 InterfaceStats `json:",inline"`
184
185 Interfaces []InterfaceStats `json:"interfaces,omitempty"`
186}
187
188// CPUStats contains data about CPU usage.
189type CPUStats struct {
190 // The time at which these stats were updated.
191 Time metav1.Time `json:"time"`
192 // Total CPU usage (sum of all cores) averaged over the sample window.
193 // The "core" unit can be interpreted as CPU core-nanoseconds per second.
194 // +optional
195 UsageNanoCores *uint64 `json:"usageNanoCores,omitempty"`
196 // Cumulative CPU usage (sum of all cores) since object creation.
197 // +optional
198 UsageCoreNanoSeconds *uint64 `json:"usageCoreNanoSeconds,omitempty"`
199}
200
201// MemoryStats contains data about memory usage.
202type MemoryStats struct {
203 // The time at which these stats were updated.
204 Time metav1.Time `json:"time"`
205 // Available memory for use. This is defined as the memory limit - workingSetBytes.
206 // If memory limit is undefined, the available bytes is omitted.
207 // +optional
208 AvailableBytes *uint64 `json:"availableBytes,omitempty"`
209 // Total memory in use. This includes all memory regardless of when it was accessed.
210 // +optional
211 UsageBytes *uint64 `json:"usageBytes,omitempty"`
212 // The amount of working set memory. This includes recently accessed memory,
213 // dirty memory, and kernel memory. WorkingSetBytes is <= UsageBytes
214 // +optional
215 WorkingSetBytes *uint64 `json:"workingSetBytes,omitempty"`
216 // The amount of anonymous and swap cache memory (includes transparent
217 // hugepages).
218 // +optional
219 RSSBytes *uint64 `json:"rssBytes,omitempty"`
220 // Cumulative number of minor page faults.
221 // +optional
222 PageFaults *uint64 `json:"pageFaults,omitempty"`
223 // Cumulative number of major page faults.
224 // +optional
225 MajorPageFaults *uint64 `json:"majorPageFaults,omitempty"`
226}
227
228// AcceleratorStats contains stats for accelerators attached to the container.
229type AcceleratorStats struct {
230 // Make of the accelerator (nvidia, amd, google etc.)
231 Make string `json:"make"`
232
233 // Model of the accelerator (tesla-p100, tesla-k80 etc.)
234 Model string `json:"model"`
235
236 // ID of the accelerator.
237 ID string `json:"id"`
238
239 // Total accelerator memory.
240 // unit: bytes
241 MemoryTotal uint64 `json:"memoryTotal"`
242
243 // Total accelerator memory allocated.
244 // unit: bytes
245 MemoryUsed uint64 `json:"memoryUsed"`
246
247 // Percent of time over the past sample period (10s) during which
248 // the accelerator was actively processing.
249 DutyCycle uint64 `json:"dutyCycle"`
250}
251
252// VolumeStats contains data about Volume filesystem usage.
253type VolumeStats struct {
254 // Embedded FsStats
255 FsStats
256 // Name is the name given to the Volume
257 // +optional
258 Name string `json:"name,omitempty"`
259 // Reference to the PVC, if one exists
260 // +optional
261 PVCRef *PVCReference `json:"pvcRef,omitempty"`
262}
263
264// PVCReference contains enough information to describe the referenced PVC.
265type PVCReference struct {
266 Name string `json:"name"`
267 Namespace string `json:"namespace"`
268}
269
270// FsStats contains data about filesystem usage.
271type FsStats struct {
272 // The time at which these stats were updated.
273 Time metav1.Time `json:"time"`
274 // AvailableBytes represents the storage space available (bytes) for the filesystem.
275 // +optional
276 AvailableBytes *uint64 `json:"availableBytes,omitempty"`
277 // CapacityBytes represents the total capacity (bytes) of the filesystems underlying storage.
278 // +optional
279 CapacityBytes *uint64 `json:"capacityBytes,omitempty"`
280 // UsedBytes represents the bytes used for a specific task on the filesystem.
281 // This may differ from the total bytes used on the filesystem and may not equal CapacityBytes - AvailableBytes.
282 // e.g. For ContainerStats.Rootfs this is the bytes used by the container rootfs on the filesystem.
283 // +optional
284 UsedBytes *uint64 `json:"usedBytes,omitempty"`
285 // InodesFree represents the free inodes in the filesystem.
286 // +optional
287 InodesFree *uint64 `json:"inodesFree,omitempty"`
288 // Inodes represents the total inodes in the filesystem.
289 // +optional
290 Inodes *uint64 `json:"inodes,omitempty"`
291 // InodesUsed represents the inodes used by the filesystem
292 // This may not equal Inodes - InodesFree because this filesystem may share inodes with other "filesystems"
293 // e.g. For ContainerStats.Rootfs, this is the inodes used only by that container, and does not count inodes used by other containers.
294 InodesUsed *uint64 `json:"inodesUsed,omitempty"`
295}
296
297// UserDefinedMetricType defines how the metric should be interpreted by the user.
298type UserDefinedMetricType string
299
300const (
301 // MetricGauge is an instantaneous value. May increase or decrease.
302 MetricGauge UserDefinedMetricType = "gauge"
303
304 // MetricCumulative is a counter-like value that is only expected to increase.
305 MetricCumulative UserDefinedMetricType = "cumulative"
306
307 // MetricDelta is a rate over a time period.
308 MetricDelta UserDefinedMetricType = "delta"
309)
310
311// UserDefinedMetricDescriptor contains metadata that describes a user defined metric.
312type UserDefinedMetricDescriptor struct {
313 // The name of the metric.
314 Name string `json:"name"`
315
316 // Type of the metric.
317 Type UserDefinedMetricType `json:"type"`
318
319 // Display Units for the stats.
320 Units string `json:"units"`
321
322 // Metadata labels associated with this metric.
323 // +optional
324 Labels map[string]string `json:"labels,omitempty"`
325}
326
327// UserDefinedMetric represents a metric defined and generate by users.
328type UserDefinedMetric struct {
329 UserDefinedMetricDescriptor `json:",inline"`
330 // The time at which these stats were updated.
331 Time metav1.Time `json:"time"`
332 // Value of the metric. Float64s have 53 bit precision.
333 // We do not foresee any metrics exceeding that value.
334 Value float64 `json:"value"`
335}