what is the meaning of 'window' in results from k8s metric server api

583 views Asked by At

When I type this command on cli:

kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespaces/<NAMESPACE>/pods/<POD_NAME> | jq

I can get these results as below:

{
  "kind": "PodMetrics",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "name": "busybox",
    "namespace": "default",
    "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/busybox",
    "creationTimestamp": "2019-12-10T18:23:20Z"
  },
  "timestamp": "2019-12-10T18:23:12Z",
  "window": "30s",
  "containers": [
    {
      "name": "busybox",
      "usage": {
        "cpu": "0",
        "memory": "364Ki"
      }
    }
  ]
}

What is the meaning of that "window" item? I am really want to know what it is exactly.

1

There are 1 answers

2
Matt On BEST ANSWER

According to k8s source code:

// PodMetrics sets resource usage metrics of a pod.
type PodMetrics struct {
    metav1.TypeMeta
    metav1.ObjectMeta

    // The following fields define time interval from which metrics were
    // collected from the interval [Timestamp-Window, Timestamp].
    Timestamp metav1.Time
    Window    metav1.Duration

    // Metrics for all containers are collected within the same time window.
    Containers []ContainerMetrics
}

You are most likely interested in this comment:

The following fields define time interval from which metrics were collected from the interval [Timestamp-Window, Timestamp].

So the usage result is an averaged data gathered over this window/interval.