Reputation: 11
I would like to instrument queries executed via datastax java driver in Cassandra. Is extending com.datastax.driver.core.SessionManager is the way? Also if extending SessionManager I have to Instantiate it in com.datastax.driver.core.Cluster by modifying Cluster source too ? is this the best way or is there any other possible way to achieve this ?
Upvotes: 0
Views: 246
Reputation: 13707
I just collect metrics by timing the call to session.execute():
private Session session;
private AtomicLongMap<String> executeCount;
private AtomicLongMap<String> executeTime;
....
@Override
public ResultSet execute(BoundStatement statement, Object... bindVariables) {
try {
long startTime = System.currentTimeMillis();
ResultSet resultSet = session.execute(statement);
long endTime = System.currentTimeMillis();
executeCount.incrementAndGet(command);
executeTime.addAndGet(command, endTime - startTime);
return resultSet;
} catch (IllegalArgumentException e) {
LOG.error("IllegalArgumentException executing:" + command + ":" + Arrays.toString(bindVariables));
throw e;
}
}
Upvotes: 1