'Can't scrape metrics from Cassandra docker container with cassandra exporter

I'm trying to monitor Cassandra that is running in a docker container with this cassandra-exporter . For some reasons the cassandra-exporter can't scrape the metrics from cassandra, if I use docker logs -f cassandra-exporter I get the following output:

Waiting for Cassandra JMX to start on  localhost:7199

I think that the exporter is running fine. Do I have to open other ports for the cassandra container? Or am I missing some environment variables?

Here are my running containers:

CONTAINER ID        IMAGE                                                    COMMAND                  CREATED             STATUS              PORTS                                                                                                      NAMES
7fe7e4e568fa        criteord/cassandra_exporter:latest   "/sbin/dumb-init /bi…"   11 minutes ago      Up 11 minutes       0.0.0.0:8080->8080/tcp                                                                                     cassandra-exporter
84375b95a8eb        cassandra:3.11.4                     "docker-entrypoint.s…"   11 minutes ago      Up 11 minutes       0.0.0.0:7000-7001->7000-7001/tcp, 0.0.0.0:7199->7199/tcp, 0.0.0.0:9042->9042/tcp, 0.0.0.0:9160->9160/tcp   cassandra

This is my docker-compose.yml file:

version: '3.6'

services:
  cassandra:
    image: cassandra:3.11.4
    container_name: cassandra
    ports:
      - "9042:9042"
      - "9160:9160"
      - "7199:7199"
      - "7000:7000"
      - "7001:7001"
    volumes:
      - type: bind
        source: /root/jmxremote.password
        target: /etc/java-8-openjdk/management/jmxremote.password
        read_only: true
      - type: bind
        source: /data
        target: /var/lib/cassandra/
      - type: bind
        source: /root/jmxremote.password
        target: /etc/cassandra/jmxremote.password
        read_only: true
    environment:
      - JVM_OPTS=-Djava.rmi.server.hostname=<ip-address>
      - LOCAL_JMX=no
      - CASSANDRA_BROADCAST_ADDRESS=<ip-address>
      - CASSANDRA_START_RPC=true
    restart: always

  cassanadra-exporter:
    image: criteord/cassandra_exporter:latest
    container_name: cassandra-exporter
    ports:
      - "8080:8080"
    volumes:
      - type: bind
        source: /root/cassandra_exporter/cassandra.yml
        target: /etc/cassandra/cassandra.yml
        read_only: true
    restart: always


Solution 1:[1]

I came across this, while googling the same issue (waiting for JMX) I manage to solve it in my usecase, but we might differ in environments, seems to me you are including all I had to do already.

I am running on docker swarm, cassandra and exporter are both on same network. Config for exporter is default other than host. Relevant parts of docker compose I had to add to solve the issue:

services:
  cassandra-exporter1:
    image: criteord/cassandra_exporter
    environment:
      - CASSANDRA_EXPORTER_CONFIG_host=cassandra:7199 #alias on the network
  cassandra:
    environment:
      - LOCAL_JMX=no
      - JVM_EXTRA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false"

Since I am not exposing the JMX port to the outside world, I can turn off the auth entirely. With this the exporter immediately managed to connect.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vilda