Thanks to visit codestin.com
Credit goes to github.com

Skip to content

zacker330/Java-JMX-example

Repository files navigation

An example of JMX

WARNING: all examples base on Java8.

startup

use mvn to package our java code: mvn compile package then:

java \
-jar ./target/jmxexample-1.0-SNAPSHOT.jar \
-javaagent ./libs/jolokia-jvm-1.3.7-agent.jar=port=7777,host=localhost \
codes.showme.App 

P.S. add this parameter if your jconsole can't connect to app's jmx port: -Djava.rmi.server.hostname=127.0.0.1

setup jconsole log for debugging

jconsole -J-Djava.util.logging.config.file=/Users/jack/codebase/open-sources/jmxexample/jconsole-log4j.properties \
127.0.0.1:9999

authorization

simple username/password

  1. create an access file for defining roles, like jmxremote.access in our example:

    monitorRole   readonly
    controlRole   readwrite
    
  2. create a password file, like jmxremote.password in our example:

    ## Defining two "roles", each with its own password
    monitorRole  derbym
    controlRole  derby
    

    then chmod 400 jmxremote.password to prevent error: Error: Password file read access must be restricted: jmxremote.password

  3. add parameter to your command line:

    -Dcom.sun.management.jmxremote.access.file=jmxremote.access \
    -Dcom.sun.management.jmxremote.password.file=jmxremote.password \
    

    and have to set -Dcom.sun.management.jmxremote.authenticate=true

Using third jvm agent: jolokia

  1. download jolokia-jvm-agent to libsfolder.
  2. run example app with jolokia-jvm-agent:
    java \
    -javaagent:./libs/jolokia-jvm-1.3.7-agent.jar=port=7777,host=localhost \
    -jar ./target/jmxexample-1.0-SNAPSHOT.jar \
    codes.showme.App
  3. read jmx mbean data in browser: http://127.0.0.1:7777/jolokia/read/java.lang:type=Memory/HeapMemoryUsage/ you should get reference of Jolokia protocol
  4. more about jolokia jvm agent
  5. fortunately, a kind someone create a dashboard named jolokia-web for displaying jolokia data:

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages