Header Ads Widget

Responsive Advertisement

JConsole Monitoring for Java Standalone or Web application project


To monitor your Java applications, including your Apache server running on Windows, you can use jconsole (Java Monitoring and Management Console). jconsole is a graphical tool that allows you to monitor and manage Java applications in real-time, using Java Management Extensions (JMX).

Here's a guide on how to use jconsole for monitoring:

Step 1: Enable JMX in Your Java Application

To use jconsole, your Java application must be started with JMX monitoring enabled. This involves adding a few JVM options.

  1. Edit the startup script or command for your Java application to include the JMX options. For example:
Java project


package com.jconsole.example;

public class ThreadProcess implements Runnable{

 @Override
 public void run() {

  int count=0;
  while(true){
   System.out.println("Count method test by JConsole"+count++);
  }
 }

}


package com.jconsole.example;

public class ThreadProcessDemo {

 public static void main(String[] args) {
     ThreadProcess tProcess=new ThreadProcess();
     Thread t=new Thread(tProcess);
     t.start();
     System.out.println("Main Thread is running");
 }

}

sh

java -Dcom.sun.management.jmxremote \

     -Dcom.sun.management.jmxremote.port=9010 \

     -Dcom.sun.management.jmxremote.authenticate=false \

     -Dcom.sun.management.jmxremote.ssl=false \

     -jar your-application.jar

 

  • -Dcom.sun.management.jmxremote enables JMX monitoring.
  • -Dcom.sun.management.jmxremote.port=9010 sets the JMX port to 9010 (you can choose another port).
  • -Dcom.sun.management.jmxremote.authenticate=false disables authentication (for simplicity; not recommended for production).
  • -Dcom.sun.management.jmxremote.ssl=false disables SSL (for simplicity; not recommended for production).

Step 2: Start jconsole

  1. Open jconsole from your JDK bin directory. On Windows, you can typically find it here:

sh

C:\Program Files\Java\jdk<version>\bin\jconsole.exe

  1. Start jconsole from the command line by typing:

sh

jconsole

 

Step 3: Connect to Your Java Application

  1. Local Connection: If you are running the application locally, jconsole will display a list of local processes. Select your Java application from the list and click "Connect".
  2. Remote Connection: If you are monitoring a remote application or if your local application does not appear in the list, select the "Remote Process" option and enter the connection details:
    • Remote Process: hostname:port (e.g., localhost:9010)
  3. If any firewall issue please ignore this. Then click unsecure.
  4. Click "Connect" to establish the connection.

 

 

Fig 1
Fig 1

 


Fig 2
Fig 2

 

Fig 3
Fig 3


Fig 4
Fig 4


Step 4: Monitor Your Application from Fig 4

Once connected, jconsole provides several tabs for monitoring various aspects of your application:

  1. Overview: Provides a summary of CPU usage, memory usage, thread activity, and classes loaded.
  2. Memory: Allows you to monitor memory usage, including heap and non-heap memory, garbage collection, and memory pools.
  3. Threads: Shows the number of active threads and their states, and allows you to perform thread dumps.
  4. Classes: Displays the number of loaded classes and their loading/unloading trends.
  5. VM Summary: Provides detailed information about the JVM, including system properties and JVM arguments.
  6. MBeans: Allows you to browse and interact with the MBeans registered in your application. You can view and modify attributes, invoke operations, and subscribe to notifications.

Example: Monitoring an Apache Server Running as a Java Application

If you are running an Apache server with Tomcat or another Java-based web server, you can enable JMX for Tomcat and monitor it using jconsole. For example, to enable JMX in Tomcat:

  1. Edit the catalina.bat or catalina.sh file (depending on your operating system) in the bin directory of your Tomcat installation.
  2. Add the following JVM options to the CATALINA_OPTS environment variable:

Sh

set CATALINA_OPTS=-Dcom.sun.management.jmxremote ^

                   -Dcom.sun.management.jmxremote.port=9010 ^

                   -Dcom.sun.management.jmxremote.ssl=false ^

                   -Dcom.sun.management.jmxremote.authenticate=false

 

  1. Start Tomcat using the modified script.
  2. Connect to Tomcat using jconsole as described above.

Security Considerations

For production environments, it is recommended to enable authentication and SSL for JMX connections to secure access to your application:

  • Authentication: Use the -Dcom.sun.management.jmxremote.password.file and -Dcom.sun.management.jmxremote.access.file options to specify the password and access files.
  • SSL: Use the -Dcom.sun.management.jmxremote.ssl=true option and configure the necessary SSL properties.

Documentation and Further Reading

By following these steps, you can effectively monitor your Java applications and Apache servers using jconsole.






Post a Comment

0 Comments