public interface Metrics
MetricRegistry
to expose the driver's metrics.
This type exists mainly to avoid a hard dependency to Dropwizard Metrics (that is, the JAR can be completely removed from the classpath if metrics are disabled). It also provides convenience methods to access individual metrics programmatically.
Modifier and Type | Method and Description |
---|---|
default <T extends com.codahale.metrics.Metric> |
getNodeMetric(Node node,
NodeMetric metric)
Shortcut for
getNodeMetric(node, metric,
null) . |
<T extends com.codahale.metrics.Metric> |
getNodeMetric(Node node,
NodeMetric metric,
String profileName)
Retrieves a node-level metric for a given node from the registry.
|
com.codahale.metrics.MetricRegistry |
getRegistry()
Returns the underlying Dropwizard registry.
|
default <T extends com.codahale.metrics.Metric> |
getSessionMetric(SessionMetric metric)
Shortcut for
getSessionMetric(metric, null) . |
<T extends com.codahale.metrics.Metric> |
getSessionMetric(SessionMetric metric,
String profileName)
Retrieves a session-level metric from the registry.
|
@NonNull com.codahale.metrics.MetricRegistry getRegistry()
Typically, this can be used to configure a reporter.
@NonNull <T extends com.codahale.metrics.Metric> Optional<T> getSessionMetric(@NonNull SessionMetric metric, @Nullable String profileName)
To determine the type of each metric, refer to the comments in the default reference.conf
(included in the driver's codebase and JAR file). Note that the method does not
check that this type is correct (there is no way to do this at runtime because some metrics are
generic); if you use the wrong type, you will get a ClassCastException
in your code:
// Correct:
Gauge<Integer> connectedNodes = getSessionMetric(DefaultSessionMetric.CONNECTED_NODES);
// Wrong, will throw CCE:
Counter connectedNodes = getSessionMetric(DefaultSessionMetric.CONNECTED_NODES);
profileName
- the name of the execution profile, or null
if the metric is not
associated to any profile. Note that this is only included for future extensibility: at
this time, the driver does not break up metrics per profile. Therefore you can always use
getSessionMetric(SessionMetric)
instead of this method.@NonNull default <T extends com.codahale.metrics.Metric> Optional<T> getSessionMetric(@NonNull SessionMetric metric)
getSessionMetric(metric, null)
.@NonNull <T extends com.codahale.metrics.Metric> Optional<T> getNodeMetric(@NonNull Node node, @NonNull NodeMetric metric, @Nullable String profileName)
To determine the type of each metric, refer to the comments in the default reference.conf
(included in the driver's codebase and JAR file). Note that the method does not
check that this type is correct (there is no way to do this at runtime because some metrics are
generic); if you use the wrong type, you will get a ClassCastException
in your code:
// Correct:
Gauge<Integer> openConnections = getNodeMetric(node, DefaultNodeMetric.OPEN_CONNECTIONS);
// Wrong, will throw CCE:
Counter openConnections = getNodeMetric(node, DefaultNodeMetric.OPEN_CONNECTIONS);
profileName
- the name of the execution profile, or null
if the metric is not
associated to any profile. Note that this is only included for future extensibility: at
this time, the driver does not break up metrics per profile. Therefore you can always use
getNodeMetric(Node, NodeMetric)
instead of this method.@NonNull default <T extends com.codahale.metrics.Metric> Optional<T> getNodeMetric(@NonNull Node node, @NonNull NodeMetric metric)
getNodeMetric(node, metric,
null)
.Copyright © 2017–2024. All rights reserved.