How to enable the Prometheus in Cassandra

How to enable the Prometheus in Cassandra

How to Enable Prometheus Mode in Apache Cassandra

This article explains how to configure Apache Cassandra to expose metrics in Prometheus format using JMX Exporter. Once configured, Applications Manager can collect Cassandra metrics using Prometheus mode.


1. Overview

Apache Cassandra exposes runtime metrics through Java Management Extensions (JMX). To make these metrics available in Prometheus format, the Prometheus JMX Exporter must be configured as a Java Agent within the Cassandra JVM.

After configuration, Cassandra metrics will be available through an HTTP endpoint:

http://<Hostname>:7071/metrics

2. Prerequisites

  • Apache Cassandra is installed and running.
  • Root or sudo access to the Cassandra server.
  • Prometheus JMX Exporter JAR file available on the server.
  • Port 7071 available for exposing metrics.

3. Create JMX Exporter Directory

sudo mkdir -p /opt/jmx_exporter

Copy the JMX Exporter JAR into the directory:

/opt/jmx_exporter/jmx_prometheus_javaagent.jar

4. Create Exporter Configuration File

Create the configuration file:

sudo vi /opt/jmx_exporter/cassandra.yml

Add the following configuration:

startDelaySeconds: 0
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true

rules:
- pattern: ".*"

This configuration exports all available Cassandra JMX metrics.


5. Configure Cassandra JVM

Edit the Cassandra environment configuration file:

sudo vi /etc/cassandra/cassandra-env.sh

Add the following line at the end of the file:

JVM_OPTS="$JVM_OPTS -javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent.jar=7071:/opt/jmx_exporter/cassandra.yml"

This configuration instructs Cassandra to load the JMX Exporter and expose metrics through port 7071.


6. Restart Cassandra

sudo systemctl restart cassandra

Verify Cassandra status:

sudo systemctl status cassandra

Expected:

Active: active (running)

7. Verify Metrics Endpoint

Verify that the exporter is listening on port 7071:

sudo ss -ltnp | grep 7071

Access the metrics endpoint:

curl http://<hostname>:7071/metrics

Successful output should display Prometheus-formatted metrics similar to:

# HELP jvm_memory_bytes_used
# TYPE jvm_memory_bytes_used gauge

# HELP cassandra_storage_load
# TYPE cassandra_storage_load gauge

8. Configure Applications Manager

While creating the Cassandra monitor in Prometheus mode, provide:

FieldValue
HostCassandra Server IP
Port7071
Endpoint/metrics
ProtocolHTTP/HTTPS

9. Validation

  • Cassandra service is running.
  • Port 7071 is listening.
  • Metrics are accessible through the /metrics endpoint.
  • Applications Manager successfully discovers metrics.

10. Troubleshooting

Address Already in Use

Error:

java.net.BindException: Address already in use

The configured exporter port is already occupied by another process. Use a different port in the javaagent configuration and restart Cassandra.

Metrics Endpoint Not Accessible

Verify that Cassandra has loaded the javaagent:

ps -ef | grep java

Confirm the javaagent argument appears in the JVM startup parameters.

Cassandra Fails to Start

Review Cassandra logs:

tail -f /var/log/cassandra/system.log

Ensure the JMX Exporter JAR path and YAML configuration path are valid.


Result

Apache Cassandra is now configured to expose metrics in Prometheus format through the JMX Exporter endpoint, enabling Applications Manager to monitor Cassandra using Prometheus mode.