Use jolokia and hawtio to get MBean information etc. of Java application.
A Java agent for accessing MBeans via http. Since it can be accessed via http, MBean information can be easily collected with curl or the like. The collected information will be returned in JSON.
hawtio is a web console that allows you to monitor and manage Java applications. As standard, it supports Tomcat, Apache Camel, Apache ActiveMQ, etc. Other Java applications can also display MBean and JVM information acquired by JMX.
In JMX, hawtio does not communicate with the application by JMX, but http communication with the backend jolokia to collect MBean information and display it on the screen. In other words, hawtio and jolokia can be combined to access various remote Java applications via JMX.
This time, as a Java application to be monitored, I will try to run it using kafka that happened to be running on the server.
In addition, the procedure referred to the following article.
jolokia
Download jolokia's Agent from the following site.
https://jolokia.org/download.html
jolokia can be run standalone or embedded in a Java application.
Execute the following command to display the process list of the Java application.
# java -jar jolokia-jvm-1.6.0-agent.jar
3906 kafka.Kafka ../config/server.properties
4229 jolokia-jvm-1.6.0-agent.jar
1039 org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/kafka/config/zookeeper.properties
The command options are as follows.
Usage: java -jar jolokia-jvm-1.6.0-agent.jar [options] <command> <pid/regexp>
where <command> is one of
start -- Start a Jolokia agent for the process specified
stop -- Stop a Jolokia agent for the process specified
status -- Show status of an (potentially) attached agent
toggle -- Toggle between start/stop (default when no command is given)
list -- List all attachable Java processes (default when no argument is given at all)
encrypt -- Encrypt a password which is given as argument or read from standard input
Next, run jolokia as follows. The last "3906" is the process ID of the Java application to be monitored. "Http://127.0.0.1:8778/jolokia/" displayed on the screen after execution will be the access destination to jolokia. The user ID and password for authentication of jolokia are "jolokia".
# java -jar jolokia-jvm-1.6.0-agent.jar --user jolokia --password jolokia start 3906
Started Jolokia for PID 3906
http://127.0.0.1:8778/jolokia/
Add the following to your Java startup options: Change the path of "jolokia-jvm-1.6.0-agent.jar" according to your environment.
-javaagent:./jolokia-jvm-1.6.0-agent.jar=port=8778,host=localhost
Access jolokia via http and try to get the version information.
# curl http://localhost:8778/jolokia/version
{"request":{"type":"version"},"value":{"agent":"1.6.0","protocol":"7.2","config":{"listenForHttpService":"true","maxCollectionSize":"0","authIgnoreCerts":"false","agentId":"192.168.10.141-4698-5b480cf9-jvm","debug":"false","agentType":"jvm","policyLocation":"classpath:\/jolokia-access.xml","agentContext":"\/jolokia","serializeException":"false","mimeType":"text\/plain","maxDepth":"15","authMode":"basic","discoveryEnabled":"true","streaming":"true","canonicalNaming":"true","historyMaxEntries":"10","allowErrorDetails":"true","allowDnsReverseLookup":"true","realm":"jolokia","includeStackTrace":"true","maxObjects":"0","useRestrictorService":"false","debugMaxEntries":"100"},"info":{"product":"jetty","vendor":"Eclipse","version":"9.2.24.v20180105"}},"timestamp":1542198764,"status":200}[root@kafkaserver1 ~]#
Next, try accessing jolokia via http to get the metrics.
# curl http://localhost:8778/jolokia/read/java.lang:type=Memory/NonHeapMemoryUsage
{"request":{"mbean":"java.lang:type=Memory","attribute":"NonHeapMemoryUsage","type":"read"},"value":{"init":2555904,"committed":53477376,"max":-1,"used":50092648},"timestamp":1542198810,"status":200}[root@kafkaserver1 ~]#
To stop Jolokia, execute the following command.
# java -jar jolokia-jvm-1.6.0-agent.jar stop 3906
Stopped Jolokia for PID 3906
Download the hawtio module from the following site. This time, I downloaded "hawtio-app-2.3.0.jar".
https://github.com/hawtio/hawtio/releases
Run hawtio with the following command. "--Port 8090" specifies the port used by hawtio.
java -jar hawtio-app-2.3.0.jar --port 8090
hawtio: Don't cha wish your console was hawt like me!
=====================================================
The URL of the hawtio web console is as follows.
http://localhost:8090/hawtio
When you open it with a browser, the following screen will be displayed.
I will try to connect to jolokia immediately.
First, click the "Add connection" button. A dialog for entering jolokia connection information will be displayed. Enter it as shown on the screen.
When you click "Test Connection", the dialog for entering the user ID and password of jolokia is displayed. Enter the "jolokia" that was set when jolokia was started.
If "Connected successfully" is displayed, it is successful. Finally, click the "Add" button.
Click the "Connect" button to open another window.
Select the JMX tab to see information about kafka's MBeans.
You can see information about the JVM's System Properties, threads, Class Histogram, etc. in the Runtime.
-Visualize Camel web application deployed on Tomcat9 with hawtio
Recommended Posts