Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor java application memory usage in Docker

I run the java web application on tomcat in the Docker container.

Is there any way to monitor the memory usage of the java application? I try to use jconsole with the process id of the docker, but it tells me Invalidate process id

I also enable JMX in tomcat, but don't know how to bind to it. I can use visualvm from my local to bind the host machine, but can not find way to bind to the docker inner the host.

Is there any good way to achieve this?

Thanks

like image 908
Browny Lin Avatar asked Apr 16 '14 08:04

Browny Lin


People also ask

How does docker calculate memory usage?

On Linux, the Docker CLI reports memory usage by subtracting cache usage from the total memory usage. The API does not perform such a calculation but rather provides the total memory usage and the amount from the cache so that clients can use the data as needed.

How do I check memory container usage?

Run the docker stats command to display the status of your containers. Memory is listed under the MEM USAGE / LIMIT column. This provides a snapshot of how much memory the container is utilizing and what it's memory limit is. CPU utilization is listed under the CPU % column.


1 Answers

To connect to a java process running in a docker container running in boot2docker with visualvm you can try the following:

Start your java process using the following options:

java -Dcom.sun.management.jmxremote.port=<port> \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.rmi.port=<port> \
-Djava.rmi.server.hostname=<boot2docker_ip> \
<Main>

You need to run your image with --expose <port> -p <port>:<port>.

Then "Add JMX Connection" in visualvm with <boot2docker_ip>:<port>.

It shouldn't be much different without boot2docker.

like image 152
Pierre Mage Avatar answered Sep 20 '22 05:09

Pierre Mage