-
-
Save broilogabriel/f3dc1de535887fd0bea7104687e094c1 to your computer and use it in GitHub Desktop.
JVM monitoring in a Docker environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class BusyApp { | |
public static void main(String []args) throws Exception { | |
final java.util.Random generator = new java.util.Random(); | |
while (true) { | |
generator.ints(1000000, 0, 100).sorted(); | |
Thread.sleep(5000L); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jvmapp: | |
build: . | |
dockerfile: Dockerfile-jvmapp | |
container_name: jvmapp | |
environment: | |
JMX_HOST: jvmapp | |
JMX_PORT: 4000 | |
ports: | |
- "4000:4000" | |
jmxtrans: | |
build: . | |
dockerfile: Dockerfile-jmxtrans | |
container_name: jmxtrans | |
environment: | |
JMX_HOST: jvmapp | |
JMX_PORT: 4000 | |
STATSD_HOST: dashboard | |
STATSD_PORT: 8125 | |
links: | |
- jvmapp | |
- dashboard | |
dashboard: | |
image: kamon/grafana_graphite | |
container_name: dashboard | |
ports: | |
- "80:80" | |
- "81:81" | |
- "8125:8125/udp" | |
- "8126:8126" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:8 | |
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections | |
RUN wget http://central.maven.org/maven2/org/jmxtrans/jmxtrans/259/jmxtrans-259.deb | |
RUN dpkg -i jmxtrans-259.deb | |
COPY run-jmxtrans.sh /run-jmxtrans.sh | |
RUN chmod 755 /run-jmxtrans.sh | |
CMD /run-jmxtrans.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:8 | |
COPY BusyApp.java /BusyApp.java | |
RUN javac BusyApp.java | |
ENV JMX_HOST=jvm-app | |
ENV JMX_PORT=4000 | |
CMD java \ | |
-Djava.rmi.server.hostname=$JMX_HOST \ | |
-Dcom.sun.management.jmxremote \ | |
-Dcom.sun.management.jmxremote.port=$JMX_PORT \ | |
-Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \ | |
-Dcom.sun.management.jmxremote.local.only=false \ | |
-Dcom.sun.management.jmxremote.authenticate=false \ | |
-Dcom.sun.management.jmxremote.ssl=false \ | |
BusyApp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
JMXTRANS_HEAP_SIZE=${JMXTRANS_HEAP_SIZE:-"512"} | |
JMXTRANS_LOG_LEVEL=${JMXTRANS_LOG_LEVEL:-"info"} | |
JMXTRANS_PERIOD=${JMXTRANS_PERIOD:-"10"} | |
JMXTRANS_JAR="/usr/share/jmxtrans/lib/jmxtrans-all.jar" | |
JMXTRANS_CONFIG="/jmxtrans-config.json" | |
cat <<EOF > $JMXTRANS_CONFIG | |
{ | |
"servers": [ | |
{ | |
"host": "${JMX_HOST}", | |
"port": "${JMX_PORT}", | |
"queries": [ | |
{ | |
"obj": "java.lang:type=Memory", | |
"attr": [ "HeapMemoryUsage", "NonHeapMemoryUsage" ], | |
"outputWriters": [ | |
{ | |
"@class": "com.googlecode.jmxtrans.model.output.StdOutWriter" | |
}, | |
{ | |
"@class": "com.googlecode.jmxtrans.model.output.StatsDWriterFactory", | |
"host": "${STATSD_HOST}", | |
"port": "${STATSD_PORT}", | |
"bucketType" : "c" | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
EOF | |
JAVA_OPTS="-Xms${JMXTRANS_HEAP_SIZE}m -Xmx${JMXTRANS_HEAP_SIZE}m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true" | |
JMXTRANS_OPTS="-Djmxtrans.log.level=${JMXTRANS_LOG_LEVEL}" | |
MONITOR_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=${JMX_PORT}" | |
EXEC="-jar $JMXTRANS_JAR -e -f $JMXTRANS_CONFIG -s $JMXTRANS_PERIOD -c false" | |
java -server $JAVA_OPTS $JMXTRANS_OPTS $MONITOR_OPTS $EXEC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment