2

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.

Braiam
  • 1
  • 11
  • 47
  • 78
irrain
  • 23
  • 2
  • 1
    CPU is reported as the average usage, in CPU cores, over a period of time. This value is derived by taking a rate over a cumulative CPU counter provided by the kernel (in both Linux and Windows kernels). The kubelet chooses the window for the rate calculation. Obtained from [here](https://github.com/kubernetes-sigs/metrics-server/blob/master/FAQ.md#how-cpu-usage-is-calculated) but not sure if it is representing the same thing. – Krishna Chaurasia Jun 18 '21 at 06:56

1 Answers1

1

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.

Matt
  • 7,419
  • 1
  • 11
  • 22
  • I really really appreciate your helps. thank you very much!! – irrain Jun 21 '21 at 02:23
  • 1
    Hello @irrain, please consider accepting or upvoting the answer if you found it helpful. stackoverflow.com/help/privileges/comment – MWZ Jun 25 '21 at 12:42