有没有办法在 c# 程序中远程从 kafka 服务器获取指标? [英] Is there a way to get the metrics from a kafka server remotely in a c# program?

查看:27
本文介绍了有没有办法在 c# 程序中远程从 kafka 服务器获取指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在 c# 中的项目需要从 kafka 服务器获取未复制分区的数量.我可以在 mbeans 部分下的 jconsole 中查看它,但是我需要在 c# 程序中获取该值.我尝试使用带有此代码的 NetMX 来建立初始连接.

My current project in c# requires getting the number of under replicated partitions from a kafka server. I can view this in jconsole under the mbeans section, but I need to get the value in a c# program. I tried using NetMX with this code to make the initial connection.

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
INetMXConnector connector = NetMXConnectorFactory.Connect(new Uri("http://<myserver>:<jmxport>"), null);    
IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

在第二行抛出Section not found"错误,我想知道是否有人可以帮忙解决这个问题?

A "Section not found" error is thrown at the second line and I was wondering if anyone could help with this please?

推荐答案

1) 使用 jolokia jar 通过添加将 JMX 转换为 HTTP:

1) Use jolokia jar to convert JMX to HTTP by adding:

KAFKA_OPTS: javaagent:/usr/share/java/kafka/jolokia-jvm-1.6.0-agent.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.rmi.port=9999 -Djava.security.auth.login.config=/var/private/sasl_acl/kafka.server.jaas.config.

KAFKA_OPTS: javaagent:/usr/share/java/kafka/jolokia-jvm-1.6.0-agent.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.rmi.port=9999 -Djava.security.auth.login.config=/var/private/sasl_acl/kafka.server.jaas.config.

2) 现在您将获得一个 http 端点,您可以尝试使用示例获取请求来检查它是否有效http://localhost:8778/jolokia/read//java.lang:type=Memory/HeapMemoryUsage

2) You will get a http endpoint now you can try a sample get request to check whether it works http://localhost:8778/jolokia/read//java.lang:type=Memory/HeapMemoryUsage

3) 使用标准的 rest api 库来使用上述端点.

3) Use standard rest api libraries to consume above endpoint.

这篇关于有没有办法在 c# 程序中远程从 kafka 服务器获取指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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