Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu

Caution

You're viewing documentation for a previous version of Scylla Java Driver. Switch to the latest stable version.

Scylla Java Driver Manual Metrics

Metrics¶

The driver exposes measurements of its internal behavior through the popular Dropwizard Metrics library. Developers can access these metrics and choose to export them to a monitoring tool.

The driver depends on Metrics 3.2.x, but is compatible with newer versions of Dropwizard Metrics. For using Metrics 4.x with the driver, see Metrics 4 Compatibility.

Structure¶

Metric names are path-like, dot-separated strings. Metrics are measured at the Cluster-level, thus the driver prefixes them with the name of the Cluster they are associated with (see withClusterName for how to configure this), suffixed by -metrics. For example:

cluster1-metrics.connected-to
cluster1-metrics.connection-errors
...

Configuration¶

By default, metrics are enabled and exposed via JMX as MXBeans.

Some users may find that they don’t want the driver to record and expose metrics. To disable metrics collection, use the withoutMetrics builder method, i.e.:

Cluster cluster = Cluster.builder()
        .withoutMetrics()
        .build();

Note that if you decide to disable metrics, you may also consider excluding metrics as a dependency. To do this in a maven project:

<dependency>
  <groupId>com.scylladb</groupId>
  <artifactId>scylla-driver-core</artifactId>
  <version>3.7.2.0</version>
  <exclusions>
    <exclusion>
      <groupId>io.dropwizard.metrics</groupId>
      <artifactId>metrics-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Alternatively, one may not want to expose metrics using JMX. Disabling JMX reporting is simple as using the withoutJMXReporting builder method, i.e.:

Cluster cluster = Cluster.builder()
        .withoutJMXReporting()
        .build();

Accessing Cluster Metrics¶

Cluster metrics may be accessed via the getMetrics method. The Metrics class offers direct access to all metrics recorded for the Cluster via getter methods. Refer to the Metrics javadoc for more details about the metrics offered.

It is very common for applications to record their own metrics. You can add all metrics recorded for a Cluster to your applications’ MetricRegistry in the following manner:

MetricRegistry myRegistery = new MetricRegistry();
myRegistry.registerAll(cluster.getMetrics().getRegistry());

Registering a Custom Reporter¶

Dropwizard Metrics offers a variety of Reporters for exporting metrics. To enable reporting, access the Cluster’s metrics via the getMetrics method. For example, to enable CSV reporting every 30 seconds:

import com.codahale.metrics.*;

import java.io.File;
import java.util.concurrent.TimeUnit;

Metrics metrics = cluster.getMetrics();

CsvReporter csvReporter = CsvReporter.forRegistry(metrics.getRegistry())
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .convertRatesTo(TimeUnit.SECONDS)
        .build(new File("."));

csvReporter.start(30, TimeUnit.SECONDS);

Metrics 4 Compatibility¶

While the driver depends on Metrics 3.2.x, it also works with Metrics 4, with some caveats.

In Metrics 4, JMX reporting was moved to a separate module, metrics-jmx. Because of this you are likely to encounter the following exception at runtime when initializing a Cluster:

Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
	at com.datastax.driver.core.Metrics.<init>(Metrics.java:103)
	at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1402)
	at com.datastax.driver.core.Cluster.init(Cluster.java:159)
	at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
	at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305)
	at com.datastax.durationtest.core.DurationTest.createSessions(DurationTest.java:360)
        ....
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	... 8 more

To fix this, use withoutJMXReporting when constructing your Cluster. If you still desire JMX reporting, add metrics-jmx as a dependency:

<dependency>
  <groupId>io.dropwizard.metrics</groupId>
  <artifactId>metrics-jmx</artifactId>
  <version>4.0.2</version>
</dependency>

Then create your Cluster and JmxReporter in the following manner:

Cluster cluster = Cluster.builder()
        .withoutJMXReporting()
        .build();

JmxReporter reporter =
    JmxReporter.forRegistry(cluster.getMetrics().getRegistry())
        .inDomain(cluster.getClusterName() + "-metrics")
        .build();

reporter.start();
PREVIOUS
Metadata
NEXT
Native protocol
  • 3.7.2.x
    • 4.13.0.x
    • 4.12.0.x
    • 4.11.1.x
    • 4.10.0.x
    • 4.7.2.x
    • 3.11.2.x
    • 3.11.0.x
    • 3.10.2.x
    • 3.7.2.x
  • Scylla Java Driver for Scylla and Apache Cassandra®
  • API Documentation
  • Manual
    • Address resolution
    • Asynchronous programming
    • Authentication
    • Compression
    • Control connection
    • Custom Codecs
    • Custom Payloads
    • Query idempotence
    • Load balancing
    • Logging
    • Metadata
    • Metrics
    • Native protocol
    • Object Mapper
      • Definition of mapped classes
      • Using custom codecs
      • Using the mapper
    • OSGi
    • Paging
    • Connection pooling
    • Query timestamps
    • Reconnection
    • Retries
    • Using the shaded JAR
    • Socket options
    • Speculative query execution
    • SSL
    • Statements
      • Simple statements
      • Prepared statements
      • Built statements
      • Batch statements
    • Using Tuples with the Java driver
    • User-defined types
  • Upgrade guide
    • Migrating from Astyanax
      • Configuration
      • Language change : from Thrift to CQL
      • Queries and Results
  • Frequently Asked Questions
  • Changelog
  • Create an issue
  • Edit this page

On this page

  • Metrics
    • Structure
    • Configuration
    • Accessing Cluster Metrics
    • Registering a Custom Reporter
    • Metrics 4 Compatibility
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© 2022, ScyllaDB. All rights reserved.
Last updated on 25 May 2022.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2