I am trying to get the CPU usage from the /apis/events.k8s.io/v1beta1
endpoint in the kubernetes internal api.
I run the following command
kubectl proxy --port=8080
Then load the url http://localhost:8080/apis/metrics.k8s.io/v1beta1/pods and get a response similar to this one
{
"kind": "PodMetricsList",
"apiVersion": "metrics.k8s.io/v1beta1",
"metadata": {
"selfLink": "/apis/metrics.k8s.io/v1beta1/pods"
},
"items": [
{
"metadata": {
"name": "name-of-the-container-667656d796-p586s",
"namespace": "namespace-name",
"selfLink": "/apis/metrics.k8s.io/v1beta1/pods/name-of-the-container-667656d796-p586s",
"creationTimestamp": "2019-11-20T21:34:02Z"
},
"timestamp": "2019-11-20T21:33:02Z",
"window": "30s",
"containers": [
{
"name": "name-of-the-container",
"usage": {
"cpu": "350748682n",
"memory": "238860Ki"
}
}
]
}
]
}
The cpu value is 350748682n
. From this discussion n
is "1/1000000000 (1 billionth) of a cpu"
I am also seeing values like 14513u
I have reviewed the quantity definition but do not see anything referencing u
What are all the possible units used to report this metric?
u
is a simplification of the lowercase Greek mu (μ) which means 10^-6, aka "micro-cpus". The unit is always the same, it's in terms of CPU cores. Metrics-server tries to report in nano-cpus for maximum accuracy, but if the number won't fit in an int64, it will change the scaling factor until it fits.