danielqsj / kafka_exporter

Kafka exporter for Prometheus
Apache License 2.0
2.1k stars 602 forks source link

Kafka exporter unable to open connection to broker : connection refused #391

Closed tanguynicolas closed 1 year ago

tanguynicolas commented 1 year ago

Hello,

I have a very simple Kafka configuration, but Kafka exporter container fail to connect to it anytimes.

This command works: kafka-topics.sh --version --bootstrap-server 127.0.0.1:9094

There is my Kafka configuration:

      KAFKA_ENABLE_KRAFT: yes                   # Default
      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true # Default
      ALLOW_PLAINTEXT_LISTENER: yes             # Dev only (no SASL_SSL)
      KAFKA_CFG_LISTENERS: INSIDE://kafka:9092,OUTSIDE://kafka:9094,CONTROLLER://:9093
      KAFKA_CFG_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9094
      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT,CONTROLLER:PLAINTEXT
      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: INSIDE
      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_OPTS: -javaagent:/bitnami/kafka/jmx_prometheus_javaagent.jar=12345:/bitnami/kafka/config/config.yaml

When I run docker run --rm -p 9308:9308 danielqsj/kafka-exporter --kafka.server=127.0.0.1:9094 --kafka.version=3.4.0 I get:

I0605 21:08:08.525811       1 kafka_exporter.go:800] Starting kafka_exporter (version=1.7.0, branch=master, revision=a1d846df120ec306e2ca36557ccba5e697f1229f)
F0605 21:08:09.279575       1 kafka_exporter.go:901] Error Init Kafka Client: kafka: client has run out of available brokers to talk to: dial tcp 127.0.0.1:9094: connect: connection refused

I don't understand why :/ Could you help me?

Thanks for your sources, TN

Zhanganjin0520 commented 1 year ago

I run the same cmd in windows docker desktop, and have the same error image My kafka version is 3.4.0 and the server.properties is default

tanguynicolas commented 1 year ago

In this command I specify localhost, which can't work because my container's localhost is taken into account. Sorry for the inconvenience, it's been a long evening.

But problem still persist with kafka:9092

tanguynicolas commented 1 year ago

Ok I find the real solution.

Do not put hostname (kafka) below when using multi networks, cause Kafka will resolve it with IP of its own interface in FIRST network (by alphabetic order)

# DON'T USE
KAFKA_CFG_LISTENERS: INSIDE://kafka:9092,OUTSIDE://kafka:9094,CONTROLLER://:9093

# USE
KAFKA_CFG_LISTENERS: INSIDE://:9092,OUTSIDE://:9094,CONTROLLER://:9093

So the problem isn't Kafka Exporter problem.