CqlSession.getMetrics() returning null value, even after configuration for enabling the metrics has been added to it.
@Autowired
private CqlSession cqlsession;
MetricRegistry metricRegistry = cqlsession.getMetrics()
.orElseThrow(() -> new IllegalArgumentException("not able to get metrics"))
.getRegistry();
application.properties:
datastax-java-driver.advanced.metrics {
session.enabled = [connected-nodes, cql-requests]
node.enabled = [pool.open-connections, pool.in-flight]
}
Comment From: wilkinsona
Your application.properties configuration doesn't look like it is in the correct format. It looks like Cassandra driver's .conf file format to me. Perhaps a typo in the file's name in the description above?
Using application.conf won't fix your problem as, when using Spring Boot's auto-configuration of Cassandra's Driver, application.conf is not used. The supported mechanisms for configuring Cassandra are described in the documentation. In your case, you should use a DriverConfigLoaderBuilderCustomizer bean:
@Bean
DriverConfigLoaderBuilderCustomizer metricsCustomizer() {
return (builder) -> {
builder.withStringList(DefaultDriverOption.METRICS_SESSION_ENABLED,
Arrays.asList("connected-nodes", "cql-requests"));
builder.withStringList(DefaultDriverOption.METRICS_NODE_ENABLED,
Arrays.asList("pool.open-connections", "pool.in-flight"));
};
}
We should probably update the documentation to clarify that application.conf is not used by the auto-configured DriverConfigLoader.
Comment From: Esakkimuthu991
Your
application.propertiesconfiguration doesn't look like it is in the correct format. It looks like Cassandra driver's.conffile format to me. Perhaps a typo in the file's name in the description above?Using
application.confwon't fix your problem as, when using Spring Boot's auto-configuration of Cassandra's Driver,application.confis not used. The supported mechanisms for configuring Cassandra are described in the documentation. In your case, you should use aDriverConfigLoaderBuilderCustomizerbean:
java @Bean DriverConfigLoaderBuilderCustomizer metricsCustomizer() { return (builder) -> { builder.withStringList(DefaultDriverOption.METRICS_SESSION_ENABLED, Arrays.asList("connected-nodes, cql-requests")); builder.withStringList(DefaultDriverOption.METRICS_NODE_ENABLED, Arrays.asList("pool.open-connections", "pool.in-flight")); }; }We should probably update the documentation to clarify that
application.confis not used by the auto-configuredDriverConfigLoader.
After changing my code to use above as suggested.
Its Skip the properties and returns empty as earlier for cqlsession.getMetrics()
Comment From: wilkinsona
Sorry, that was a typo in my code snippet. I've edited it above to correct it. It should have read Arrays.asList("connected-nodes", "cql-requests") rather than Arrays.asList("connected-nodes, cql-requests").
Comment From: Esakkimuthu991
Sorry, that was a typo in my code snippet. I've edited it above to correct it. It should have read
Arrays.asList("connected-nodes", "cql-requests")rather thanArrays.asList("connected-nodes, cql-requests").
Thanks Solved my problem