0

I'm trying to get mbeans of Kafka using Java code ( consumer or producer ) like they appear in jconsole In jconsole I can see the name of the mbean ( like : objetName:kafka.consumer:type=consumer-fetch-manager-metrics,client-id=consumer-1)

so here is my code :

JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi");

where port is like in the config file ( server.properties) that I set (I set port in Kafka config file ( SET JMX_PORT=9098 ) , I also tried to use my Kafka port ( 9092) but than I get address in use -

 bean=new ObjectName("kafka.consumer:type=consumer-coordinator-metrics,client-id=consumer-1");
MBeanInfo info= connection.getMBeanInfo(bean);

I get InstanceNotFoundException

when I use this code :

domains=connection.getDomains();

I get all the domains except kafka.consumer ( i.e java.nio,java.util.logging , java.lang .. etc ) but not the kafka.server even though I can see the kafka.consumer mbeans in Jconsole ..

but, I don't know how to access the JMXServiceURL: I tried to give the folloiwing : new

I also tries this :

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

but after I get the server bean , I cannot see Kafka mbeans (just other custom mbeans that i created or others but not Kafka mbeans )

I think that Kafka exposes the port to jconsole in some port which I cannot figure it

Any ideas ?

Elad Leev
  • 908
  • 7
  • 17
eyalmar100
  • 41
  • 1
  • 1
  • 4
  • Your code says port 9998, but you used 9098 in the bat file? (you shouldn't edit the bat file, anyway, and JMX isn't defined in server.properties ) – OneCricketeer Feb 16 '21 at 15:08
  • The problem is that I don't know what is the connection string :i.e :JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); what is th port that the kafka server expose the mbeans ? – eyalmar100 Feb 17 '21 at 15:06
  • By default, it doesn't. That's why you set the variable before starting the broker in the terminal, but if you want to connect to it, then use the same port – OneCricketeer Feb 17 '21 at 15:15
  • Did you see this post? https://stackoverflow.com/questions/36708384/how-to-enable-remote-jmx-on-kafka-brokers-for-jmxtool – OneCricketeer Feb 17 '21 at 15:18

0 Answers0