<p>I am using metrics-server(<a href="https://github.com/kubernetes-incubator/metrics-server/" rel="nofollow noreferrer">https://github.com/kubernetes-incubator/metrics-server/</a>) to collect the core metrics from containers in a kubernetes cluster.</p>

<p>I could fetch 2 resource usage metrics per container.</p>

<ul>
<li>cpu usage</li>
<li>memory usage</li>
</ul>

<p>However its not clear to me whether </p>

<ul>
<li><p>these metrics are accumulated over time or they are already sampled for a particular time window(1 minute/ 30 seconds..)</p></li>
<li><p>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.</p></li>
<li><p>While computing CPU usage metric value, does metrics-server already take care of dividing the container usage by the host system usage?</p></li>
</ul>

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

<p>Thanks!</p>

Venkat Teki
<ol>
<li>Metrics are scraped periodically from kubelets. The default resolution duration is 60s, which can be overriden with the <code>--metric-resolution=&lt;duration&gt;</code> flag.</li>
<li>The value and unit (cpu - cores in decimal SI, memory - bytes in binary SI) are arrived at by using the <code>Quantity</code> serializer in the k8s <a href="https://github.com/kubernetes/apimachinery" rel="nofollow noreferrer">apimachinery</a> package. You can read about it from the comments in the <a href="https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go" rel="nofollow noreferrer">source code</a></li>
<li>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.<br>
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 <code>/pods</code> and <code>/nodes</code> endpoints.</li>
</ol>
