发现 Cassandra Java 应用程序所做的所有查询的好方法是什么? [英] What is a good way to discover all queries made by a Cassandra java app?

查看:15
本文介绍了发现 Cassandra Java 应用程序所做的所有查询的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 SQL 数据库,我可以只在驱动程序上打开日志记录以查看进行了哪些查询……或者如果我可以访问数据库服务器,则将它们记录在服务器端.

For a SQL db, I could just turn on logging on the driver to see what queries were made... or log them on the server side if I had access to the db server.

这是如何在 Cassandra 中实现的?

How is this accomplished in Cassandra ?

推荐答案

您可以通过 QueryLogger.

QueryLogger 为客户端提供了记录驱动程序执行的查询的能力,特别是,它允许客户端跟踪慢查询,即完成时间超过以毫秒为单位的配置阈值的查询.

The QueryLogger provides clients with the ability to log queries executed by the driver, and especially, it allows client to track slow queries, i.e. queries that take longer to complete than a configured threshold in milliseconds.

QueryLogger 示例代码

QueryLogger Example Code

try (Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withCredentials("username", "password").build(); Session session = cluster.connect("test")) {
    QueryLogger queryLogger = QueryLogger.builder()
            .withConstantThreshold(500)
            .build();
    cluster.register(queryLogger);
    for (Row row : session.execute("select userid, firstname from users limit 10")) {
        System.out.println(row);
    }
}

这里 withConstantThreshold(500) 表示超过 1000 毫秒的查询将被视为慢查询

Here withConstantThreshold(500) means the query which takes longer than 1000 milliseconds will treat as slow query

使用以毫秒为单位的恒定阈值来跟踪慢查询的 QueryLogger.此实现是默认实现,应该优先于仍处于测试状态的 QueryLogger.DynamicThresholdQueryLogger.

A QueryLogger that uses a constant threshold in milliseconds to track slow queries. This implementation is the default and should be preferred to QueryLogger.DynamicThresholdQueryLogger which is still in beta state.

并且您需要将记录器级别设置为 DEBUG 启用查询日志记录

and You need to set your logger level to DEBUG turn Query Logging enable

这篇关于发现 Cassandra Java 应用程序所做的所有查询的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆