<p>I monitor the eks cluster using both the kubernetes api and the kube state metrics remotely using prometheus.
in Kubernetes api we have a metrics <strong><code>container_cpu_usage_seconds_total</code></strong> which gives the cpu usage of the pod.
is there a similar metrics in kube-state-metrics which can give the cpu usage.
Actually I'm trying to get the cluster cpu usage which is totally different from kubernetes api and kube-state-metrics
following are the calculations.</p>

<p><strong><code>kube-state-metrics:</code></strong></p>

<p><code>sum(kube_pod_container_resource_requests_cpu_cores) / sum(kube_node_status_allocatable_cpu_cores) * 100</code> - This gives 101%</p>

<p>whereas the kube-state-metrics gives <code>12%</code> which looks accurate to me.</p>

<p><strong><code>kubernetes-api:</code></strong></p>

<p><code>sum (rate (container_cpu_usage_seconds_total{id="/",kubernetes_io_hostname=~"^$Node$",  job=~"$job$"}[5m])) / sum (machine_cpu_cores{kubernetes_io_hostname=~"^$Node$",  job=~"$job$"}) * 100</code></p>

<p>I don't think there's any metric in kube-state-metric which gives cpu usage compared to kubernetes-api</p>

<p>Thanks in advance.</p>

Amjad Hussain Syed
<p>No, there is no (one) specific metric for cpu usage per container in <strong>kube_state_metric.</strong></p>
<p>The value you got:
<code> sum(kube_pod_container_resource_requests_cpu_cores) / sum(kube_node_status_allocatable_cpu_cores) * 100 = 101</code>
may be wrong because metrics like <strong>kube_node_status_allocatable_cpu_cores</strong> and <strong>kube_pod_container_resource_requests_cpu_cores</strong> are marked as <strong>DEPRECATED</strong>.</p>
<p>At the same time, take notice that there is metric like <strong>kube_pod_container_resource_limits_cpu_cores</strong>.
Your container could have set resource limit, that's why probably your result exceed <strong>100 %</strong>. If you have limit set per container check if resource limit is lower than resource request and then your calculation should looks like:
<code> [sum(kube_pod_container_resource_requests_cpu_cores) - sum(kube_pod_container_resource_limits_cpu_cores)]/ sum(kube_node_status_allocatable_cpu_cores) * 100</code>.</p>
<p>Take a look at every resource metrics in <strong>kube_state_metrics</strong> for container and nodes:
<a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/node-metrics.md" rel="nofollow noreferrer">node_metrics</a>, <a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/pod-metrics.md" rel="nofollow noreferrer">pod_container_metrics</a>.</p>
