<p>I would like to know how to get current or the last read metric value of CPU and memory usage of all pods.</p>

<p>I tried to call the hawkler endpoint. I went to the browser developer mode by hitting f12 and took this endpoint from list of calls that are made when metrics page of a pod is loaded.</p>

<pre><code>https://metrics.mydev.abccomp.com/hakular/metrics/gauges/myservice%dfjlajdflk-lkejre-12112kljdfkl%2Fcpu%2Fusage_rate/data?bucketDuration=1mn&amp;start=-1mn
</code></pre>

<p>However this will give me the cpu usage metrics for the last minute, for that particular pod. I am trying to see if there is a command or way exisits that will give me only the current snapshot of cpu usage and memory stats of all the pods collectively like below:</p>

<pre><code>pod        memory usage     memory max       cpu usage         cpu max
pod1       0.4 mb            2.0 mb            20 m cores       25 m cores
pod2       1.5 mb            2.0 mb            25 m cores       25 m cores 
</code></pre>

lr-pal
<p>To see the pods that use the most cpu and memory you can use the <a href="https://www.mankier.com/1/kubectl-top-pod" rel="nofollow noreferrer">kubectl top</a> command but it doesn't sort yet and is also missing the quota limits and requests per pod. You only see the current usage.</p>

<p>Execute command below:</p>

<pre><code>$ kubectl top pods --all-namespaces --containers=true
</code></pre>

<p>Because of these limitations, but also because you want to gather and store this resource usage information on an ongoing basis, a monitoring tool comes in handy. This allows you to analyze resource usage both in real time and historically, and also lets you alert on capacity bottlenecks.</p>

<p>To workaround problem " Error from server (Forbidden): unknown (get services http:heapster"</p>

<p>Make sure that heapster deployment don't forgot to install the Service for heapster, otherwise you will have to do it manually.</p>

<p>E.g.:</p>

<pre><code>$ kubectl create -f /dev/stdin &lt;&lt;SVC
apiVersion: v1
kind: Service
metadata:
  name: heapster
  namespace: kube-system
spec:
  selector:
    whatever-label: is-on-heapster-pods
  ports:
  - name: http
    port: 80
    targetPort: whatever-is-heapster-is-listening-on
SVC
</code></pre>
