在Java中使用JMX读取Cassandra矩阵 [英] Read cassandra matrics using JMX in Java

查看:79
本文介绍了在Java中使用JMX读取Cassandra矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JMX / Metrics在Java中生成Cassandra的实时指标?我想运行cassandra JMX命令来收集cassandra矩阵。示例将不胜感激。

How can i produce live metrics of Cassandra in Java using JMX/Metrics? I want to run cassandra JMX command to collect cassandra matrices.Examples will be much appreciated.

推荐答案

所有通过JMX公开的Cassandra指标<官方文档中记录了href = http://cassandra.apache.org/doc/latest/operating/metrics.html rel = nofollow noreferrer> 。并且由于它使用了Metrics库,因此您可能不需要使用JMX来捕获指标-有关更多信息(和 conf / metrics-reporter-config-sample,请参阅参考页末尾的注释。 yaml (来自Cassandra发行版的示例文件)。

All Cassandra's metrics exposed via JMX are documented in official documentation. And because it uses the Metrics library, you may not need to use JMX to capture metrics - see the note at the end of the referenced page for more information (and conf/metrics-reporter-config-sample.yaml example file from Cassandra's distribution).

PS也许我误解了这个问题-您能提供更多详细信息吗?您是否正在寻找从Cassandra收集指标的命令?还是Java中的代码段?

P.S. Maybe I misunderstood the question - can you provide more details? Are you looking for commands to collect that metrics from Cassandra? Or code snippets in Java?

从Java中,您可以通过以下方式访问特定指标:

From Java you can access the particular metrics with something like this:

JMXServiceURL url = new JMXServiceURL(
    "service:jmx:rmi:///jndi/rmi://[127.0.0.1]:7199/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

Set<ObjectInstance> objs = mbsc.queryMBeans(ObjectName
                                        .getInstance("org.apache.cassandra.metrics:type=ClientRequest,scope=Read-ALL,name=TotalLatency"), null);
for (ObjectInstance obj : objs) {
    Object proxy = JMX.newMBeanProxy(mbsc, obj.getObjectName(),
       CassandraMetricsRegistry.JmxCounterMBean.class);
    if (proxy instanceof CassandraMetricsRegistry.JmxCounterMBean) {
        System.out.println("TotalLatency = " + ((CassandraMetricsRegistry.JmxCounterMBean) proxy).getCount());
    }
}
jmxc.close();

更详细的示例可以在 JmxCollector

More detailed example you can find at JmxCollector from cassandra-metrics-collector project...

这篇关于在Java中使用JMX读取Cassandra矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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