我想检测通过Cassandra中的datastax java驱动程序执行的查询。是扩展com.datastax.driver.core.SessionManager的方法吗?另外,如果扩展SessionManager,我也必须通过修改Cluster source在com.datastax.driver.core.Cluster中实例化它吗?
这是最好的方法还是有其他可能的方法来实现?

最佳答案

我只是通过计时对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;
    }
}

关于java - 如何扩展Cassandra SessionManager for Instrumentation,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25989680/

10-14 10:59