Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Created July 26, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waleedsamy/dbf20d301573c08a8834755f96ad5e6c to your computer and use it in GitHub Desktop.
Save waleedsamy/dbf20d301573c08a8834755f96ad5e6c to your computer and use it in GitHub Desktop.
Run java/jmx in docker container and use visaulvm to mointor your app

I was testing an application (parser.jar) and need to limit the resource used by the app (cpu/ram) and see how different implmenation behaves.

docker run --rm -p 9010:9010 -it --memory=3000MB --cpus="2" java:8-jdk bash -c " java \
      -server \
      -XX:+UseG1GC \
      -XX:+UseStringDeduplication \
      -XX:+ExitOnOutOfMemoryError \
      -Xmx2g \
      -Dcom.sun.management.jmxremote.port=9010 \
      -Dcom.sun.management.jmxremote.authenticate=false \
      -Dcom.sun.management.jmxremote.ssl=false \
      -Dcom.sun.management.jmxremote.rmi.port=9010 \
      -Djava.rmi.server.hostname=$HOST_HOSTNAME \
     -jar target/scala-2.11/parser.jar"

Then from visualvm, add JMX by using the docker interface ip (im my case, en0 wit ip 172.18.10.13) and port exposed from previous command (9010)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment