Skip to content

Instantly share code, notes, and snippets.

@babadofar
Last active March 12, 2020 20:48
kubernetes cpu metricbeat
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"
}
}
}
}
}
}
}
}
@babadofar
Copy link
Author

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

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