Class Metrics


  • public class Metrics
    extends Object
    Metrics exposed by the driver.

    The metrics exposed by this class use the Metrics library and you should refer its documentation for details on how to handle the exposed metric objects.

    By default, metrics are exposed through JMX, which is very useful for development and browsing, but for production environments you may want to have a look at the reporters provided by the Metrics library which could be more efficient/adapted.

    • Method Detail

      • getRegistry

        public com.codahale.metrics.MetricRegistry getRegistry()
        Returns the registry containing all metrics.

        The metrics registry allows you to easily use the reporters that ship with Metrics or a custom written one.

        For instance, if metrics is this object, you could export the metrics to csv files using:

             com.codahale.metrics.CsvReporter.forRegistry(metrics.getRegistry()).build(new File("measurements/")).start(1, TimeUnit.SECONDS);
         

        If you already have a MetricRegistry in your application and wish to add the driver's metrics to it, the recommended approach is to use a listener:

             // Your existing registry:
             final com.codahale.metrics.MetricRegistry myRegistry = ...
        
             cluster.getMetrics().getRegistry().addListener(new com.codahale.metrics.MetricRegistryListener() {
                 @Override
                 public void onGaugeAdded(String name, Gauge<?> gauge) {
                     if (myRegistry.getNames().contains(name)) {
                         // name is already taken, maybe prefix with a namespace
                         ...
                     } else {
                         myRegistry.register(name, gauge);
                     }
                 }
        
                 ... // Implement other methods in a similar fashion
             });
         
        Since reporting is handled by your registry, you'll probably also want to disable JMX reporting with Cluster.Builder.withoutJMXReporting().
        Returns:
        the registry containing all metrics.
      • getRequestsTimer

        public com.codahale.metrics.Timer getRequestsTimer()
        Returns metrics on the user requests performed on the Cluster.

        This metric exposes

        • the total number of requests.
        • the requests rate (in requests per seconds), including 1, 5 and 15 minute rates.
        • the mean, min and max latencies, as well as latency at a given percentile.
        Returns:
        a Timer metric object exposing the rate and latency for user requests.
      • getErrorMetrics

        public Metrics.Errors getErrorMetrics()
        Returns an object grouping metrics related to the errors encountered.
        Returns:
        an object grouping metrics related to the errors encountered.
      • getKnownHosts

        public com.codahale.metrics.Gauge<Integer> getKnownHosts()
        Returns the number of Cassandra hosts currently known by the driver (that is whether they are currently considered up or down).
        Returns:
        the number of Cassandra hosts currently known by the driver.
      • getConnectedToHosts

        public com.codahale.metrics.Gauge<Integer> getConnectedToHosts()
        Returns the number of Cassandra hosts the driver is currently connected to (that is have at least one connection opened to).
        Returns:
        the number of Cassandra hosts the driver is currently connected to.
      • getOpenConnections

        public com.codahale.metrics.Gauge<Integer> getOpenConnections()
        Returns the total number of currently opened connections to Cassandra hosts.
        Returns:
        The total number of currently opened connections to Cassandra hosts.
      • getTrashedConnections

        public com.codahale.metrics.Gauge<Integer> getTrashedConnections()
        Returns the total number of currently "trashed" connections to Cassandra hosts.

        When the load to a host decreases, the driver will reclaim some connections in order to save resources. No requests are sent to these connections anymore, but they are kept open for an additional amount of time (PoolingOptions.getIdleTimeoutSeconds()), in case the load goes up again. This metric counts connections in that state.

        Returns:
        The total number of currently trashed connections to Cassandra hosts.
      • getInFlightRequests

        public com.codahale.metrics.Gauge<Integer> getInFlightRequests()
        Returns the total number of in flight requests to Cassandra hosts.
        Returns:
        The total number of in flight requests to Cassandra hosts.
      • getRequestQueueDepth

        public com.codahale.metrics.Gauge<Integer> getRequestQueueDepth()
        Returns the total number of enqueued requests on all Cassandra hosts.
        Returns:
        The total number of enqueued requests on all Cassandra hosts.
        See Also:
        Session.State#getRequestQueueDepth(Host)
      • getExecutorQueueDepth

        public com.codahale.metrics.Gauge<Integer> getExecutorQueueDepth()
        Returns the number of queued up tasks in the main internal executor.

        If the executor's task queue is not accessible – which happens when the executor is not an instance of ThreadPoolExecutor – then this gauge returns -1.

        Returns:
        The number of queued up tasks in the main internal executor, or -1, if that number is unknown.
      • getBlockingExecutorQueueDepth

        public com.codahale.metrics.Gauge<Integer> getBlockingExecutorQueueDepth()
        Returns the number of queued up tasks in the blocking executor.

        If the executor's task queue is not accessible – which happens when the executor is not an instance of ThreadPoolExecutor – then this gauge returns -1.

        Returns:
        The number of queued up tasks in the blocking executor, or -1, if that number is unknown.
      • getReconnectionSchedulerQueueSize

        public com.codahale.metrics.Gauge<Integer> getReconnectionSchedulerQueueSize()
        Returns the number of queued up tasks in the reconnection executor.

        A queue size > 0 does not necessarily indicate a backlog as some tasks may not have been scheduled to execute yet.

        If the executor's task queue is not accessible – which happens when the executor is not an instance of ThreadPoolExecutor – then this gauge returns -1.

        Returns:
        The size of the work queue for the reconnection executor, or -1, if that number is unknown.
      • getTaskSchedulerQueueSize

        public com.codahale.metrics.Gauge<Integer> getTaskSchedulerQueueSize()
        Returns the number of queued up tasks in the scheduled tasks executor.

        A queue size > 0 does not necessarily indicate a backlog as some tasks may not have been scheduled to execute yet.

        If the executor's task queue is not accessible – which happens when the executor is not an instance of ThreadPoolExecutor – then this gauge returns -1.

        Returns:
        The size of the work queue for the scheduled tasks executor, or -1, if that number is unknown.
      • getShardAwarenessInfo

        public com.codahale.metrics.Gauge<Map<Host,​Integer>> getShardAwarenessInfo()
      • getBytesSent

        public com.codahale.metrics.Meter getBytesSent()
        Returns the number of bytes sent so far.

        Note that this measures unencrypted traffic, even if SSL is enabled (the probe is inserted before SSL handlers in the Netty pipeline). In practice, SSL overhead should be negligible after the initial handshake.

        Returns:
        the number of bytes sent so far.
      • getBytesReceived

        public com.codahale.metrics.Meter getBytesReceived()
        Returns the number of bytes received so far.

        Note that this measures unencrypted traffic, even if SSL is enabled (the probe is inserted before SSL handlers in the Netty pipeline). In practice, SSL overhead should be negligible after the initial handshake.

        Returns:
        the number of bytes received so far.