Configure jvm agent to act as a jolokia proxy

classic Classic list List threaded Threaded
2 messages Options
subburathinamv subburathinamv
Reply | Threaded
Open this post in threaded view
|

Configure jvm agent to act as a jolokia proxy

Is it possible to configure a agent as a jolokia proxy so that it can talk to other jvms and get the mbean information

For example , I have a tomcat application and I followed the below steps .

Steps :
1. I have configured this application as jolokia agent with the below params
            -javaagent:jolokia-agent.jar=port=8779,host=localhost
             
2. Restart tomcat application.

Access : http://localhost:8779/jolokia/ and it worked fine.

3. Can I configure this tomcat application to act as my jolokia proxy as well so that it can query for mbean information from other jvm's as well.

I was thinking that I can change the agent configuration in step 1 to use JSR160 dispatcher

-javaagent:jolokia-agent.jar=port=8779,host=localhost,dispatcherClasses=org.jolokia.jsr160.Jsr160RequestDispatcher

and access the jmx info of another jvm using the below post request

 curl -X POST http://localhost:8779/jolokia/ -d '{"type":"READ", "mbean":"java.lang:type=Threading", "attribute":"ThreadCount","target": { "url":"service:jmx:rmi:///jndi/rmi://localhost:9004/jmxrmi" }}'

There is another java process that has jmx enabled on port 9004 and I am trying to get the thread count.

Response :

curl -X POST http://localhost:8779/jolokia/ -d '{"type":"READ", "mbean":"java.lang:type=Threading", "attribute":"ThreadCount","target": { "url":"service:jmx:rmi:///jndi/rmi://localhost:9004/jmxrmi" }}'
{"request":{"mbean":"java.lang:type=Threading","attribute":"ThreadCount","type":"read","target":{"url":"service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:9004\/jmxrmi"}},"stacktrace":"java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]\n\tat javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)\n\tat javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:249)\n\tat org.jolokia.jsr160.Jsr160RequestDispatcher.dispatchRequest(Jsr160RequestDispatcher.java:80)\n\tat org.jolokia.backend.BackendManager.callRequestDispatcher(BackendManager.java:411)\n\tat org.jolokia.backend.BackendManager.handleRequest(BackendManager.java:158)\n\tat org.jolokia.http.HttpRequestHandler.executeRequest(HttpRequestHandler.java:197)\n\tat org.jolokia.http.HttpRequestHandler.handlePostRequest(HttpRequestHandler.java:137)\n\tat org.jolokia.jvmagent.JolokiaHttpHandler.executePostRequest(JolokiaHttpHandler.java:259)\n\tat org.jolokia.jvmagent.JolokiaHttpHandler.doHandle(JolokiaHttpHandler.java:199)\n\tat org.jolokia.jvmagent.JolokiaHttpHandler.handle(JolokiaHttpHandler.java:173)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)\n\tat sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)\n\tat sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)\n\tat com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)\n\tat sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]\n\tat javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)\n\tat javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)\n\tat javax.naming.InitialContext.init(InitialContext.java:244)\n\tat javax.naming.InitialContext.<init>(InitialContext.java:216)\n\tat javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955)\n\tat javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1924)\n\tat javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)\n\t... 18 more\nCaused by: java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:381)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n\tat java.lang.Class.forName0(Native Method)\n\tat java.lang.Class.forName(Class.java:348)\n\tat com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)\n\tat com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)\n\tat javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)\n\t... 24 more\n","error_type":"java.io.IOException","error":"java.io.IOException : Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]","status":500}

Any idea if I am missing something ?

If I configure all the java processes with jolokia agents on different port , It will work. I don't want to configure jolokia on all the java processes. I need one of the jolokia jvm agents to act as a proxy and get me the jmx info from the other processes.

roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Configure jvm agent to act as a jolokia proxy

Can you access the target, JSR-160 exposed, server with a standard JMX tool like jconsole ?  For it feels like the JMX parameters on the servers end is not configured properly.

The stacktrace indicates that Jolokia has problems to create a RMIConnector because of some weird configuration in the Tomcat ("org.apache.naming.java.javaURLContextFactory missing")

If you can connect, can you please open an issue at https://github.com/rhuss/jolokia/issues so that we can track down the problem with proxy used by an JVM agent. The normal usage for the proxy is with the WAR Jolokia agent, but it should work with the JVM agent, too.

Could you try to use e.g. a Jetty as proxy ?
... roland