Query on kubernetes metrics-server metrics values

4/15/2019

I am using metrics-server(https://github.com/kubernetes-incubator/metrics-server/) to collect the core metrics from containers in a kubernetes cluster.

I could fetch 2 resource usage metrics per container.

  • cpu usage
  • memory usage

However its not clear to me whether

  • these metrics are accumulated over time or they are already sampled for a particular time window(1 minute/ 30 seconds..)

  • What are the units for the above metric values. For CPU usage, is it the number of cores or milliseconds? And for memory usage i assume its the bytes usage.

  • While computing CPU usage metric value, does metrics-server already take care of dividing the container usage by the host system usage?

Also, if i have to compare these metrics with the docker-api metrics, how to compute CPU usage % for a given container?

Thanks!

-- Venkat Teki
docker-api
kubernetes
metrics

1 Answer

6/13/2019
  1. Metrics are scraped periodically from kubelets. The default resolution duration is 60s, which can be overriden with the --metric-resolution=<duration> flag.
  2. The value and unit (cpu - cores in decimal SI, memory - bytes in binary SI) are arrived at by using the Quantity serializer in the k8s apimachinery package. You can read about it from the comments in the source code
  3. No, the CPU metric is not relative to the host system usage as you can see that it's not a percentage value. It represents the rate of change of the total amount of CPU seconds consumed by the container by core. If this value increases by 1 within one second, the pod consumes 1 CPU core (or 1000 milli-cores) in that second.
    To arrive at a relative value, depending on your use case, you can divide the CPU metric for a pod by that for the node, since metrics-server exposes both /pods and /nodes endpoints.
-- anukul
Source: StackOverflow