Giter Club home page Giter Club logo

docker-jmx-demo's Introduction

docker-jmx-demo

A simple demo getting JMX metrics from a docker container

This demo is a Docker container that starts a simple Java application with pre-configured JMX options. Manipulating the options and running a container and JMX console in different modes demonstrates different cases of JMX monitoring. In all variants, JMX is bound to the port 9010, so JConsole will always be connecting a remote host hostname:9010, even when running locally.

Build an image

Run the docker build command in the project's directory.

docker build -t banging-daemon .

Bridge networking mode

Bridge mode is the default for a Docker container. In this mode only the published container's ports are accessible

Local JConsole

However, when running JConsole on the same machine, RMI options do not need to be advertised. The following lines of the Dockerfile may stay disabled.

#"-Dcom.sun.management.jmxremote.rmi.port=9010", \
#"-Djava.rmi.server.hostname=192.168.0.101", \

Run the container publishing the JMX remote port 9010.

docker run -it --rm --name hammer -p 9010:9010 banging-daemon

Remote JConsole

When JConsole is running on a different machine, RMI options have to be set, as a randomly RMI port is not accessible by the remote machine. It is convenient to set the port com.sun.management.jmxremote.rmi.port to the same value as com.sun.management.jmxremote.port, which is 9010 in this configuration. Using same port number makes one port mapping configuration less in a Docker container and eventually in a firewall. Parameter java.rmi.server.hostname should point at a host where Docker is running.

"-Dcom.sun.management.jmxremote.rmi.port=9010", \
"-Djava.rmi.server.hostname=192.168.0.101", \

Host networking mode

In the host mode, the container's network is not encapsulated at all. It is accessible alongside the host's network. In this case the RMI options do not need to be configured.

#"-Dcom.sun.management.jmxremote.rmi.port=9010", \
#"-Djava.rmi.server.hostname=192.168.0.101", \

Running JConsole locally or remotely does not make any difference.

The JMX remote port does not need to be published:

docker run -it --rm --net=host --name hammer banging-daemon

docker-jmx-demo's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.