This discussion is archived
4 Replies Latest reply: Aug 7, 2010 5:54 AM by 843798 RSS

Regarding JMX

843798 Newbie
Currently Being Moderated
Hi All,

Here, this is Narayana, working on JMX to develop web-based monitoring tool.

While going thru documents, I found few issues. Please can anybody help on high priority-base as its very urgent for me.

Requirement:

Ihave two machines which , one called as server machine and another called Client machine.

Here, on Server Machien my tomact-based applications running and I want to monitor those applicaitons by establishing the connection using JMX.

Here, I wrote two programs one called as "Server.java"--her I used the below code to establish the connection
----
System.setProperty("http.proxyHost", "dctmgsx");
               System.setProperty("http.proxyPort", "1099");
               
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://dctmgsx:1099/jmxrmi");
Map environment = null;
MBeanServer mbs = MBeanServerFactory.createMBeanServer();

System.out.println("cs.getAddress()+2");
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
System.out.println("cs.getAddress()+3");
cs.start();
---
And, the another program called "Client.java", whch has the below code
----
public static void main(String[] args) {
          try {
          System.out.println("\nCreate an RMI connector client and connect it to the RMI connector server");
          
          JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://dctmgsx:1099/jmxrmi");
          JMXConnector jmxc = JMXConnectorFactory.connect(url);
          
          ClientListener listener = new ClientListener();
          MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
          String domains[] = mbsc.getDomains();
          for (int i = 0; i < domains.length; i++) {
          System.out.println("\tDomain["+ i + "] = " + domains);
          }
          } catch (Exception e) {
          System.err.println("Error: " + e.getMessage());
          }
          }
     
     public static class ClientListener implements NotificationListener {
          public void handleNotification(Notification notification, Object handback) {
          System.out.println("\nReceived notification: " + notification);
          }

     }
----
when I rin the Servert.java,

its giving the following error.

     java.io.IOException: Cannot bind to URL [rmi://dctmgsx:1099/jmxrmi]: javax.naming.ServiceUnavaila
va.rmi.ConnectException: Connection refused to host: dctmgsx; nested exception is:
java.net.ConnectException: Connection refused: connect]
at javax.management.remote.rmi.RMIConnectorServer.newIOException(Unknown Source)
at javax.management.remote.rmi.RMIConnectorServer.start(Unknown Source)
at com.example.Server.main(Server.java:113)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connecti
om; nested exception is:
        java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.rmi.registry.RegistryContext.bind(Unknown Source)
at com.sun.jndi.toolkit.url.GenericURLContext.bind(Unknown Source)
at javax.naming.InitialContext.bind(Unknown Source)
at javax.management.remote.rmi.RMIConnectorServer.bind(Unknown Source)
... 2 more
Caused by: java.rmi.ConnectException: Connection refused to host: dctmgsx.yash.com; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
... 6 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)


My questions, is it required to run both programs or not. if it requires Server and Client programs, on which machine I need to run those two programs
Pls suggenst me on the same
Its very very urgent.

even I sent ssl,authenticate, remote port(1099) and host name(dctmgsx) to classpath.
Pls provide soem steps how canI establish the connection with remote machine to get/read/instrument the applicaiton/system.

Advance thanks to one and all.

Thanks
Narayana
  • 1. Re: Regarding JMX
    791266 Explorer
    Currently Being Moderated
    Munnelli wrote:
    Hi All,

    Here, this is Narayana, working on JMX to develop web-based monitoring tool.
    Monitoring what? Your tool should probably connect to other "things" that are exposing data through JMX, so your tool is a client.

    Kaj
  • 2. Re: Regarding JMX
    843798 Newbie
    Currently Being Moderated
    Hi Narayana,

    From your post I understand that you are trying to monitor a remote Tomcat server from a client machine. If I got your requirement correct, you can follow the steps given below to design your solution.
    1. Set the JMX remote port of the Tomcat server you want to monitor. This can be done by setting the JVM startup options.
    2. If firewall is turned on, you need to allow access to the jmx Remote port.
    3. You can use the following code snippet to connect to remote JVM through JMX and monitor runtime parmeters.
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://<hostname>:<JMXPort>/jmxrmi");
    JMXConnector jmxc = JMXConnectorFactory.connect(url);

    Thanks,
    Ratnam
  • 3. Re: Regarding JMX
    843798 Newbie
    Currently Being Moderated
    Hi Ratnam,

    Thaks for your advice on the same. Here, even I wrote teh same snippet of code for Remote Machien access may be on Tomcat/Jboss/or esle one. But, here, How can I enable or specify or connect to that particular remote port withour writing (i mean using client program only) server side program whcih runs MBeanServer..this is one doubt.

    And, another one, is it posible to access existing remote port for Tomcat/JBoss or any other server based applications.How do I find the report port which is bydefault workds using client program instead of writing server program aslo for MBeanServer.

    Pls can you provde me more suggestions how do I access the existing port or is it required to run some separate programs for the same to acces remote machine insfrastructure/monitoring.

    Here one more thing, Is it required to run remote port for ex:1088 on remote machine, is it required to run using "rmiregistry 1088" in command prompt in remote machine or not. Pls clarify my confusion.


    Thanks for the same.

    Thanks
    Narayana

    Edited by: Munnelli on Jul 21, 2010 2:35 AM
  • 4. Re: Regarding JMX
    843798 Newbie
    Currently Being Moderated
    Narayana, JVM has its own implementation of MBeanServer. So, the process that i mentioned tires to connect to that MBean Server. From your first post, i could understand that you are trying to monitor the applications hosted on Tomcat Server (or it could be Weblogic/JBoss). So, I suggested the procedure to connect to the default MBean server using the remoteJMX port and authentication made false. In this case, we need not write Server class as the MBean Server (which you are trying to create in Server.java) is already present. You just need to use client.java to connect to it.

    Form you reply, i could understand that you want to connect to the existing MBeanServer of Tomcat/JBOSS...
    In that case set the java_options in tomcat server startup script as follows:
    set %JAVA_OPTIONS%= %JAVA_OPTIONS% -Dcom.sun.management.jmxremote.port=<portNum> -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
    (+This enbles port for remotely connecting to existing MBeanServer+)
    Once you start teh server after update, ou check whether the remoteJMX port is enable or not using JConsole.exe(connect using JMXServiceURL).
    and follow the steps mentioned in my previous post to successfully connect to the Server. I could connect to the remote server using the above process without executing any other command at the command prompt. For further details on the same you can refer to the following link :
    http://download-llnw.oracle.com/javase/1.5.0/docs/guide/management/agent.html


    Thanks,
    Ratnam

    Edited by: Ratnam.a on Aug 7, 2010 12:49 PM

    Edited by: Ratnam.a on Aug 7, 2010 12:53 PM