Skip to content

Instantly share code, notes, and snippets.

@abiydv
Created September 30, 2021 16:11
Show Gist options
  • Save abiydv/e84aae5a07ca9f3427ddbf37bf77f9fe to your computer and use it in GitHub Desktop.
Save abiydv/e84aae5a07ca9f3427ddbf37bf77f9fe to your computer and use it in GitHub Desktop.
Pod CPU Usage
# PromQL query to calculate how much CPU a particular pod is consuming on a particular instance
# Labels available after this query - ec2 and pod
#
# Required: node_exporter exposing node_cpu* metrics
# cadvisor exposing container_cpu* metrics
#
sum(label_replace(rate(container_cpu_usage_seconds_total{cluster="k8s"}[1m]),
"ec2", "$1", "instance", "(.+):.+")) by (ec2, pod) / ignoring (pod) group_left
sum(label_replace(rate(node_cpu_seconds_total{cluster="k8s"}[1m]),
"ec2", "$1", "instance", "(.+):.+")) by (ec2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment