<p>I want to count k8s cluster cpu/memory usage (not k8s pod usage) with prometheus, so that i can show in grafana.</p>

<p>I use <code>sum (container_memory_usage_bytes{id="/"})</code> to get k8s cluster used memory, and <code>topk(1, sum(kube_node_status_capacity_memory_bytes) by (instance))</code> to get whole k8s cluster memory, but they can not divide since <code>topk</code> function does not return value but vector.</p>

<p>How can i do this?</p>

<p>I have installed Prometheus on google Cloud through the gcloud default applications. The dashboards automatically got deployed with the installation. The following queries are what was used for memory and CPU usage of the cluster:</p>

<p>CPU usage by namespace:</p>

<pre><code>sum(irate(container_cpu_usage_seconds_total[1m])) by (namespace)
</code></pre>

<p>Memory usage (no cache) by namespace:</p>

<pre><code>sum(container_memory_rss) by (namespace)
</code></pre>

<p>CPU request commitment:</p>

<pre><code>sum(kube_pod_container_resource_requests_cpu_cores) / sum(node:node_num_cpu:sum)
</code></pre>

<p>Memory request commitment:</p>

<pre><code>sum(kube_pod_container_resource_requests_memory_bytes) / sum(node_memory_MemTotal)
</code></pre>
