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

查看:82
本文介绍了发现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。此实现是默认实现,应该优先于仍处于beta状态的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天全站免登陆