Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame^] | 1 | // Copyright 2018 The Kubernetes Authors. |
| 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 sources |
| 16 | |
| 17 | import ( |
| 18 | "context" |
| 19 | "time" |
| 20 | |
| 21 | "k8s.io/apimachinery/pkg/api/resource" |
| 22 | ) |
| 23 | |
| 24 | // MetricsBatch is a single batch of pod, container, and node metrics from some source. |
| 25 | type MetricsBatch struct { |
| 26 | Nodes []NodeMetricsPoint |
| 27 | Pods []PodMetricsPoint |
| 28 | } |
| 29 | |
| 30 | // NodeMetricsPoint contains the metrics for some node at some point in time. |
| 31 | type NodeMetricsPoint struct { |
| 32 | Name string |
| 33 | MetricsPoint |
| 34 | } |
| 35 | |
| 36 | // PodMetricsPoint contains the metrics for some pod's containers. |
| 37 | type PodMetricsPoint struct { |
| 38 | Name string |
| 39 | Namespace string |
| 40 | |
| 41 | Containers []ContainerMetricsPoint |
| 42 | } |
| 43 | |
| 44 | // ContainerMetricsPoint contains the metrics for some container at some point in time. |
| 45 | type ContainerMetricsPoint struct { |
| 46 | Name string |
| 47 | MetricsPoint |
| 48 | } |
| 49 | |
| 50 | // MetricsPoint represents the a set of specific metrics at some point in time. |
| 51 | type MetricsPoint struct { |
| 52 | Timestamp time.Time |
| 53 | // CpuUsage is the CPU usage rate, in cores |
| 54 | CpuUsage resource.Quantity |
| 55 | // MemoryUsage is the working set size, in bytes. |
| 56 | MemoryUsage resource.Quantity |
| 57 | } |
| 58 | |
| 59 | // MetricSource knows how to collect pod, container, and node metrics from some location. |
| 60 | // It is expected that the batch returned contains unique values (i.e. it does not return |
| 61 | // the same node, pod, or container as any other source). |
| 62 | type MetricSource interface { |
| 63 | // Collect fetches a batch of metrics. It may return both a partial result and an error, |
| 64 | // and non-nil results thus must be well-formed and meaningful even when accompanied by |
| 65 | // and error. |
| 66 | Collect(context.Context) (*MetricsBatch, error) |
| 67 | // Name names the metrics source for identification purposes |
| 68 | Name() string |
| 69 | } |
| 70 | |
| 71 | // MetricSourceProvider provides metric sources to collect from. |
| 72 | type MetricSourceProvider interface { |
| 73 | // GetMetricSources fetches all sources known to this metrics provider. |
| 74 | // It may return both partial results and an error. |
| 75 | GetMetricSources() ([]MetricSource, error) |
| 76 | } |