Search code examples
node.jsdockercpu-usage

Does the CPU usage retrieved from node.js os.cpus() in a docker container instance indicate host CPU or container CPU?


I'm using os.cpus() to monitor my node.js app in container instances, but wonder if the usage indicates the CPU of the instance or the docker host?


Solution

  • For docker containers, there isn't a hard distinction between CPU/mem inside or outside the container like there is virtual machines. Basically, all containers share the same kernel and there isn't a namespace for CPUs or Memory that causes the container to see those differently. Thus, os.cpus() shows the usage information of the host system including all workloads. To see usage information for your containers you can use the docker stats command on the host system. For Node.js, checkout the systeminformation package which also provides usage information for docker containers. However, this is only usable if run on the host (not inside a container)!

    See also: https://docs.docker.com/engine/reference/commandline/stats/