Search code examples
javatomcatdockercpu-usagejava-melody

how to get CPU usage of tomcat running in docker container


My application setup: 4 docker containers setup by docker-compose: myapplication (tomcat, jersey application), kafka, postgres, zookeeper.

I need to know the CPU usage of tomcat container.

1, I used JavaMeloday to get % System CPU 93.36, more details.

2, I used docker stats <docker id> to get that CPU % is 356% at the same time with % System CPU 93.36 by JavaMelody.

In my machine, there are 8 cores. why the numbers in 1 and 2 are different? How to explain them?

Thanks


Solution

  • As mentioned in moby/moby issue 26711:

    800% is correct here, which is a standard notation for telling that 8 cores are 100% in use.

    So 356% means the docker container processes (not just the java Tomcat) uses almost 4 of the 8 cores.

    As opposed to Javamelody, used in "A Step-by-Step Guide to Tomcat Performance Monitoring", which monitors the Java application through JMX, and reports more: from "Java – monitoring cpu and system load of multi-threaded application via OperatingSystemMXBean", that value is an aggregate for all cores).

    The issue is: docker stats and javamelody don't monitor the activity at exactly the same time, and could report (and aggregate) different activity peaks.