robscott / kube-capacity

A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
Apache License 2.0
2.06k stars 113 forks source link

Requests calculation method with respect to pod states #125

Open bortek opened 5 months ago

bortek commented 5 months ago

Hi

I am wondering how the CPU/Mem requests are calculated with respect to the state of the pods? Ideally I want to see the numbers of the Running pods and not all of the others like Completed, Error, ImagePullErr etc.

My total numbers differ a little (607 cores versus 657 cores) if I compare the following metrics query (towards the openshift cluster ) with the output of kube-capacity like this. compute-XX is what the worker nodes are called. Master nodes and other like infra nodes are not included in the counting.

_sum(sum(kube_pod_container_resource_requests{node=~"compute.",resource="cpu"}) by (namespace, pod, node) on (namespace,pod) group_left() (sum(kube_pod_statusphase{phase="Running"}) by (pod, namespace,node) == 1))

image

kube-capacity --node-labels node-role.kubernetes.io/worker NODE CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS * 657424m (87%) 3156928m (421%) 2147320Mi (36%) 5018953Mi (86%)