Last active
March 12, 2020 20:48
kubernetes cpu metricbeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /metricbeat-*/_search | |
{ | |
"size": 0, | |
"query": { | |
"range": { | |
"@timestamp": { | |
"gte": "now-15m" | |
} | |
} | |
}, | |
"aggs": { | |
"CPURequestedPercentage": { | |
"avg_bucket": { | |
"buckets_path": "node>percentageRequested" | |
} | |
}, | |
"nodeCPUCoresAvailable": { | |
"sum_bucket": { | |
"buckets_path": "node>avgCap" | |
} | |
}, | |
"nodeCPURequested": { | |
"sum_bucket": { | |
"buckets_path": "node>nodecpurequested" | |
} | |
}, | |
"node": { | |
"terms": { | |
"field": "kubernetes.node.name", | |
"size": 10 | |
}, | |
"aggs": { | |
"percentageRequested": { | |
"bucket_script": { | |
"buckets_path": { | |
"cpuAvailable": "avgCap", | |
"cpuRequested": "nodecpurequested" | |
}, | |
"script": " params.cpuRequested / params.cpuAvailable * 100" | |
} | |
}, | |
"avgCap": { | |
"avg": { | |
"field": "kubernetes.node.cpu.capacity.cores" | |
} | |
}, | |
"nodecpurequested": { | |
"sum_bucket": { | |
"buckets_path": "pods>aggpodRequest" | |
} | |
}, | |
"pods": { | |
"terms": { | |
"field": "kubernetes.pod.name", | |
"size": 1000 | |
}, | |
"aggs": { | |
"aggpodRequest": { | |
"avg": { | |
"field": "kubernetes.container.cpu.request.cores" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using metricbeat to gather kubernetes metrics, this query will display the total amount of CPU available, the amount of CPU requested by all pods, and for extra service, this relationship as a percentage