Converting kubernetes kublet API usageNanoCore or usageCoreNanoSeconds to CPU utilization % Kubernetes kublet API

8/5/2016

I'm querying the Kubernetes kubelet API (curl -s http://localhost:10255/stats/summary) for CPU/Memory statistics and the CPU info is showing up as follows.

        "cpu": {
            "time": "2016-08-04T22:48:22Z",
            "usageNanoCores": 6392499,
            "usageCoreNanoSeconds": 3270519504746
        },

How do I convert usageNanoCores or usageCoreNanoSeconds to CPU utilization percentage?

-- Brian
cpu-usage
kubernetes

1 Answer

8/5/2016

If a process were to run on one cpu continuously for a second, its usage will be 1e+9 nanoseconds. If it ran on n cores continuously its usage will n * 1e+9 nanoseconds.

Percentage will be usage_in_nanoseconds / (capacity_in_absolute_cores * 1e+9).

*source: https://github.com/kubernetes/heapster/issues/650#issuecomment-147795824

-- janetkuo
Source: StackOverflow