`kubernetes.cpu.usage.total` is reported in nanocores
The Kubernetes integraton (https://github.com/DataDog/integrations-core/tree/master/kubernetes) provides CPU stats in two different units:
cpus (forkubernetes.cpu.limitsandkubernetes.cpu.requests)percent_nano(forkubernetes.cpu.usage.total)
These metrics are quite useful to put on the same graph in order to tune the requests/limits settings for Kubernetes containers. To do that, you have to scale kubernetes.cpu.usage.total by 1000000000 (one billion), because the value being reported by the integration is in units of nano CPUs (ie, percent_nano, though there doesn't appear to be any percent math applying. Somewhat annoyingly, you have to specify 1000000000 as (1000000 * 1000) because the web UI will otherwise convert it to 1e9 in the JSON version of a graph, but 1e9 isn't actually a valid value to scale a metric by.
The values are scraped from CAdvisor, who defines them here: https://github.com/google/cadvisor/blob/e14ee9be3506d260847d263e26a3e9e27f83ad96/info/v1/container.go#L267-L283, being pulled from the Docker daemon's statistics (https://github.com/moby/moby/blob/8b1adf55c2af329a4334f21d9444d6a169000c81/daemon/stats/collector_unix.go#L27-L71). It's essentially a rate (per second) of nanoseconds of CPU time used (thus, nanocpu).
I would like to have the values of kubernetes.cpu.usage.total appear as just "cpus" for use in DataDog. Right off the bat, two solutions jump out at me:
- scale the
kubernetes.cpu.usage.totalmetric by a billion at the agent level, and change its unit frompercent_nanotocpu- I've made a PR for this (link coming shortly) - make a new unit, nanocores, that will accept the current values being sent, but display them as cores (similar to how it seems that byte-based metrics work)
- maybe other folks have other ideas?
Hi @sophaskins,
This will be handled on the server-side without requiring potentially backwards-incompatible changes on the collection:
- we are creating a new
cpuunit family that will allow to convert between nanocores, percents and cores. All docker and kubernetes metrics will use this new family. When plottingkubernetes.cpu.usage.total, the graph will automatically scale to % (if under 100%) or cores (if over 100%) - we are implementing the possibility of graphing two metrics with different units with automatic conversion to the best common unit. This means it will be possible to graph
kubernetes.cpu.usage.totalandkubernetes.cpu.limittogether and have them scale automatically
The first part is ready, but I'm waiting on the second part from the frontend team, to release both together. ETA should be a few weeks though, as this is a significant change to the graphing code. Of course, we'll keep this issue updated when this happens.
Regards
Heya! That sounds super awesome! I like that approach - we're always glad to be guinea pigs if want beta testers :D
@xvello its been awhile since the last update, any news ?
Hi @n1koo,
The code for it is ready, but it will need extensive testing before going to production, as it could affect alerting (and no one wants false positives at 2AM). As other tasks are currently higher priority, this should be deployed at the end of October.
Sorry for the delay
Bumping this. This is a fantastic feature
@xvello Sorry for another ping but as we are at end of october, any chance of getting this in to a version in the next couple weeks?
Our team is also interested in this feature. Any update?
Any updates?
Bump.
This is still not applied?
I am also interested in this going through basically the same process!
I was able to just plot graph by scaling the percent_nano:
{
"viz": "timeseries",
"status": "done",
"requests": [
{
"q": "avg:kubernetes.cpu.usage.total{ap-southeast-1a.prod.kube.mycompany.com,app:myapp,component:sidekiq} by {kube_container_name}/1000000000",
"type": "line",
"style": {
"palette": "dog_classic",
"type": "solid",
"width": "normal"
},
"conditional_formats": [],
"aggregator": "avg"
},
{
"q": "avg:kubernetes.cpu.limits{ap-southeast-1a.prod.kube.mycompany.com,app:myapp,component:sidekiq}",
"type": "line",
"style": {
"palette": "warm",
"type": "solid",
"width": "normal"
}
},
{
"q": "avg:kubernetes.cpu.usage.total{ap-southeast-1b.prod.kube.mycompany.com,app:myapp,component:sidekiq} by {kube_container_name}/1000000000",
"type": "line",
"style": {
"palette": "dog_classic",
"type": "solid",
"width": "normal"
}
},
{
"q": "avg:kubernetes.cpu.limits{ap-southeast-1b.prod.kube.mycompany.com,app:myapp,component:sidekiq}",
"type": "line",
"style": {
"palette": "warm",
"type": "solid",
"width": "normal"
}
}
],
"autoscale": true
}
Any update on this? I have just run into the problem as well.
The work @xvello mentioned is nearing completion and has been undergoing internal testing. We will be posting some screenshots this week here in this issue for feedback.
We are going from this:

to this (today on staging):

LGTM!
Is it possible for the user to setup the label? I presume some users might like to read '3.01 cores' or '3.01 CPUs' instead of '3.01 c'.
On Tue, Mar 6, 2018 at 3:18 PM, Julien Balestra [email protected] wrote:
We are going from this: [image: img] https://camo.githubusercontent.com/917ad8b9e3cab4589b2dc6e166b98245ed0d16b2/68747470733a2f2f696d6167652e6962622e636f2f66477a4646372f6f6c642e706e67
to this (today on staging): [image: img] https://camo.githubusercontent.com/456d52aa76506aad9c6260cbe9591cdfa632ba5d/68747470733a2f2f696d6167652e6962622e636f2f6679683276372f6e616e6f646973706c61792e706e67
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DataDog/integrations-core/issues/541#issuecomment-370876762, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXvR-USqAJA8Zt8EPGGlaq7-Mp8FB6uks5tbtLEgaJpZM4OSRp- .
-- Rodrigo Aliste P.
@raliste sadly it’s not possible for users to change the units label, but you can use metric aliasing on individual charts to change the way the metric is displayed.
I set a short_name metric on cores:

In this scenario it's a 3 cores machine with a dd if=/dev/zero of=/dev/null command during few minutes in the pod sleep-f75f57b4d-7qtmm.
It's easier to correlate metrics between them.
Is this going to require Agent 6? Will the two versions result in different data? We have version 6 running only on a few machines and we're trying to explain different behaviours.
I'm also wondering if behavior has changed with agent 6. After moving to agent6 kubernetes.cpu.usage.total is missing some of the time, and the numbers don't reliably compare to kubernetes.cpu.limits in any way I can discern.
@therc The changes described here are platform side rather than agent side, so they should apply to all versions of the agent. The kubernetes integration was rewritten between 5.x and 6.x though so there are some additional tags and metrics in 6.x.
The 6.x version of the check can be found here: https://github.com/DataDog/integrations-core/tree/master/kubelet