0

I'm trying to connect the ZABBIX Java Gateway to my Kafka server through JMX. I receive a connection time out:

zabbix-java-gateway_1     | 2020-12-21 21:02:20.181 [pool-1-thread-4] WARN  com.zabbix.gateway.SocketProcessor - error processing request, item "jmx.discovery[beans,"kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec,topic=*"]" failed: Connection timed out: service:jmx:rmi:///jndi/rmi://192.168.99.100:12345/jmxrmi

Error in the GUI:

enter image description here

Kafka configuration

For Kafka I’m using the Wurstmeister Docker image. The kafka service in docker-compose.yml looks as follows:

 kafka:
    build:
      context: . 
      dockerfile: _docker/kafka/Dockerfile
    container_name: kafka
    env_file:
      - kafka/kafka.env
    environment:
      JMX_PORT: 12345
      KAFKA_JMX_OPTS: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=12345
    ports:
      - "9092:9092"
      - "12345:12345"
    depends_on:
      - zookeeper
    volumes:
      - ./kafka/volumes/data:/kafka
    networks:
      - streaming

This my my .env file for Kafka:

KAFKA_BROKER_ID=1
KAFKA_LISTENERS="INTERNAL://0.0.0.0:19092,EXTERNAL://0.0.0.0:9092"
KAFKA_ADVERTISED_LISTENERS="INTERNAL://kafka:19092,EXTERNAL://localhost:9092"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT"
KAFKA_INTER_BROKER_LISTENER_NAME="INTERNAL"
KAFKA_ZOOKEEPER_CONNECT="zookeeper:2181"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR="1"
# topic-name:partition:replication_factor:cleanup.policy:retention.ms
KAFKA_CREATE_TOPICS="iot-parser-errors:1:1:delete:7889400000,iot-raw-data:1:1:delete:604800017,iot-parsed-data:1:1:delete:2629800000,soc-data:1:1:delete:1209600033,battery-data:1:1:delete:31557600000"
KAFKA_LOG4J_LOGGERS="kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
JMX_PORT=12345
KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=12345"

ZABBIX configuration

I have set up zabbix using the the official zabbix docker image for Ubuntu with MySQL and Nginx. I copied this docker-compose file.

I have uncommented the following environment variables in .env_srv:

ZBX_JAVAGATEWAY_ENABLE=true
ZBX_JAVAGATEWAY=zabbix-java-gateway
ZBX_JAVAGATEWAYPORT=10052
ZBX_STARTJAVAPOLLERS=5

This is what my .env_java file looks like (I have increased the time out to 30):

ZBX_START_POLLERS=5
ZBX_TIMEOUT=30
# Possible values: trace, debug, info, want, error, all, off
ZBX_DEBUGLEVEL=debug

This is how I have set up the JMX interface in the zabbix GUI. I’m using the Apache Kafka by JMX template.

enter image description here

ZABBIX log

zabbix-java-gateway_1     | 2020-12-21 20:46:05.055 [pool-1-thread-4] DEBUG com.zabbix.gateway.SocketProcessor - starting to process incoming connection
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading Zabbix protocol header
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading 8 bytes of data length
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG c.z.gateway.BinaryProtocolSpeaker - reading 247 bytes of request data
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG c.z.gateway.BinaryProtocolSpeaker - received the following data in request: {"request":"java gateway jmx","username":"zabbix","password":"zabbix","jmx_endpoint":"service:jmx:rmi:///jndi/rmi://192.168.99.100:12345/jmxrmi","keys":["jmx[\"kafka.network:type=RequestMetrics,name=TemporaryMemoryBytes,request=Fetch\",\"Max\"]"]}
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG com.zabbix.gateway.SocketProcessor - dispatched request to class com.zabbix.gateway.JMXItemChecker
zabbix-java-gateway_1     | 2020-12-21 20:46:05.056 [pool-1-thread-4] DEBUG c.z.g.ZabbixJMXConnectorFactory - connecting to JMX agent at 'service:jmx:rmi:///jndi/rmi://192.168.99.100:12345/jmxrmi'
zabbix-web-nginx-mysql_1  | 172.31.0.1 - - [21/Dec/2020:21:46:10 +0100] "POST /zabbix.php?action=notifications.get&sid=fa4abac3a2f8629e&output=ajax HTTP/1.1" 200 436 "http://localhost:8081/hosts.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
zabbix-web-nginx-mysql_1  | 172.31.0.1 - - [21/Dec/2020:21:46:11 +0100] "POST /jsrpc.php?output=json-rpc HTTP/1.1" 200 74 "http://localhost:8081/hosts.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
zabbix-web-nginx-mysql_1  | 127.0.0.1 - - [21/Dec/2020:21:46:12 +0100] "GET / HTTP/1.1" 200 3624 "-" "curl/7.68.0" "-"
zabbix-web-nginx-mysql_1  | 127.0.0.1 - - [21/Dec/2020:21:46:22 +0100] "GET / HTTP/1.1" 200 3624 "-" "curl/7.68.0" "-"
zabbix-web-nginx-mysql_1  | 172.31.0.1 - - [21/Dec/2020:21:46:22 +0100] "POST /jsrpc.php?output=json-rpc HTTP/1.1" 200 74 "http://localhost:8081/hosts.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
zabbix-web-nginx-mysql_1  | 127.0.0.1 - - [21/Dec/2020:21:46:32 +0100] "GET / HTTP/1.1" 200 3624 "-" "curl/7.68.0" "-"
zabbix-web-nginx-mysql_1  | 172.31.0.1 - - [21/Dec/2020:21:46:33 +0100] "POST /jsrpc.php?output=json-rpc HTTP/1.1" 200 74 "http://localhost:8081/hosts.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
zabbix-java-gateway_1     | 2020-12-21 20:46:35.056 [pool-1-thread-4] WARN  com.zabbix.gateway.SocketProcessor - error processing request, item "jmx["kafka.network:type=RequestMetrics,name=TemporaryMemoryBytes,request=Fetch","Max"]" failed: Connection timed out: service:jmx:rmi:///jndi/rmi://192.168.99.100:12345/jmxrmi
zabbix-java-gateway_1     | 2020-12-21 20:46:35.057 [pool-1-thread-4] DEBUG com.zabbix.gateway.SocketProcessor - error caused by
zabbix-java-gateway_1     | com.zabbix.gateway.ZabbixException: Connection timed out: service:jmx:rmi:///jndi/rmi://192.168.99.100:12345/jmxrmi
zabbix-java-gateway_1     |     at com.zabbix.gateway.JMXItemChecker.getValues(JMXItemChecker.java:132) ~[zabbix-java-gateway-5.2.2.jar:na]
zabbix-java-gateway_1     |     at com.zabbix.gateway.SocketProcessor.run(SocketProcessor.java:79) ~[zabbix-java-gateway-5.2.2.jar:na]
zabbix-java-gateway_1     |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_275]
zabbix-java-gateway_1     |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_275]
zabbix-java-gateway_1     |     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_275]
zabbix-java-gateway_1     | 2020-12-21 20:46:35.057 [pool-1-thread-4] DEBUG c.z.gateway.BinaryProtocolSpeaker - sending the following data in response: {"response":"failed","error":"Connection timed out: service:jmx:rmi:\/\/\/jndi\/rmi:\/\/192.168.99.100:12345\/jmxrmi"}
zabbix-java-gateway_1     | 2020-12-21 20:46:35.057 [pool-1-thread-4] DEBUG com.zabbix.gateway.SocketProcessor - finished processing incoming connection

Kafka log

And here are the logs of the kafka container. I don’t understand why the port 12345 seems to be in use.

zabbix-java-gateway_1     |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_275]
kafka            | Error: JMX connector server communication error: service:jmx:rmi://952116a91006:12345
kafka            | sun.management.AgentConfigurationError: java.rmi.server.ExportException: Port already in use: 12345; nested exception is:
kafka            |      java.net.BindException: Address in use (Bind failed)
kafka            |      at sun.management.jmxremote.ConnectorBootstrap.exportMBeanServer(ConnectorBootstrap.java:800)
kafka            |      at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:468)
kafka            |      at sun.management.Agent.startAgent(Agent.java:262)
kafka            |      at sun.management.Agent.startAgent(Agent.java:452)
kafka            | Caused by: java.rmi.server.ExportException: Port already in use: 12345; nested exception is:
kafka            |      java.net.BindException: Address in use (Bind failed)
kafka            |      at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:346)
kafka            |      at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:254)
kafka            |      at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411)
kafka            |      at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147)
kafka            |      at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:237)
kafka            |      at sun.management.jmxremote.ConnectorBootstrap$PermanentExporter.exportObject(ConnectorBootstrap.java:199)
kafka            |      at javax.management.remote.rmi.RMIJRMPServerImpl.export(RMIJRMPServerImpl.java:146)
kafka            |      at javax.management.remote.rmi.RMIJRMPServerImpl.export(RMIJRMPServerImpl.java:122)
kafka            |      at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:404)
kafka            |      at sun.management.jmxremote.ConnectorBootstrap.exportMBeanServer(ConnectorBootstrap.java:796)
kafka            |      ... 3 more
kafka            | Caused by: java.net.BindException: Address in use (Bind failed)
kafka            |      at java.net.PlainSocketImpl.socketBind(Native Method)
kafka            |      at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
kafka            |      at java.net.ServerSocket.bind(ServerSocket.java:375)
kafka            |      at java.net.ServerSocket.<init>(ServerSocket.java:237)
kafka            |      at java.net.ServerSocket.<init>(ServerSocket.java:128)
kafka            |      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMIDirectSocketFactory.java:45)
kafka            |      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMIMasterSocketFactory.java:345)
kafka            |      at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:666)
kafka            |      at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:335)
kafka            |      ... 12 more

JMX seems to be working fine

On the Kafka side, JMX seems to be working correctly because I can establish a connection via jconsole 127.0.0.1:12345. The image below shows the Kafka MBeans.

enter image description here

What could be causing this time out?

  • `java.rmi.server.hostname=127.0.0.1` is only going to accept local connections – OneCricketeer Dec 21 '20 at 22:38
  • 1
    I have tried to enable remote connections by changing `KAFKA_JMX_OPTS` to `-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.host=0.0.0.0 -Djava.rmi.server.hostname=0.0.0.0 -Dcom.sun.management.jmxremote.rmi.port=12345 -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.local.only=false` There's still a time out. I'm not sure what the IP Adress of the JMX Interface in the Zabbix web application should represent. Should it be the IP of the Java Gateway? –  Jan 05 '21 at 08:42
  • I have based myself on this SO question: https://stackoverflow.com/questions/31257968/how-to-access-jmx-interface-in-docker-from-outside –  Jan 05 '21 at 08:46
  • Did you change the Kafka Dockerfile at all? Why can't you use `image: wurstmeister/kafka`? Also, what's in your env file? And what are you basing your IP connection in the zabbix interface on? If both are in the same docker network, you can just use kafka as the DNS name – OneCricketeer Jan 05 '21 at 14:53
  • I have modified the create-topics.sh script and I've added a volume /soc-test. This is my _docker/kafka/Dockerfile: `FROM wurstmeister/kafka COPY _scripts/create-topics.sh /usr/bin/. VOLUME ["/soc_test"] CMD ["start-kafka.sh"]` I have also opened a MR because I think this feature might be useful to others: https://github.com/wurstmeister/kafka-docker/pull/640 I have added my `kafka.env` file contents to my original post. –  Jan 07 '21 at 16:32
  • I installed ZABBIX and the Java Gateway locally on the server (i.e. no longer in Docker) and it works now with the variables specified in the .env file. I would still very much like to know how to get it working in Docker as well. –  Jan 07 '21 at 16:35
  • "And what are you basing your IP connection in the zabbix interface on?" I'm not quite sure. Besides, when I'm using zabbix inside a Docker container (on the same network as the kafka broker) I don't know which IP address I should assign to -`Djava.rmi.server.hostname`. –  Jan 07 '21 at 16:38

0 Answers0