Skip to content

Instantly share code, notes, and snippets.

@phosae
Last active January 9, 2023 13:02
Show Gist options
  • Save phosae/774b66fb98ca91e1a3cf085a0d7a9933 to your computer and use it in GitHub Desktop.
Save phosae/774b66fb98ca91e1a3cf085a0d7a9933 to your computer and use it in GitHub Desktop.
kube metrics

CPU

rate(container_cpu_usage_seconds[10m])/(container_spec_cpu_quota / container_spec_cpu_period)

by Pod and Container

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container!="POD"}[5m])) by (pod, container) 
/
sum(container_spec_cpu_quota{name!~".*prometheus.*",image!="",container!="POD"}/container_spec_cpu_period{name!~".*prometheus.*", image!="", container!="POD"}) by (pod, container) * 100

avg/max CPU usage of a set of Pods behind a App?

avg by(container) (rate(container_cpu_usage_seconds_total{container="myapp",metrics_path="/metrics/cadvisor",namespace="defualt"}[5m]) 
/ 
ignoring(cpu)
(container_spec_cpu_quota{container="myapp",metrics_path="/metrics/cadvisor",namespace="default"}/container_spec_cpu_period{container="myapp",metrics_path="/metrics/cadvisor",namespace="default"})*100)

MEM

avg/max MEM usage of a set of Pods behind a App?

avg by (container_name) (container_memory_rss{namespace="default",container_name="{{$values.app}}",metrics_path="/metrics/cadvisor"}
/
container_spec_memory_limit_bytes{namespace="default",container_name="{{$values.app}}",metrics_path="/metrics/cadvisor"}
@phosae
Copy link
Author

phosae commented Jan 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment